#    Copyright 2008, 2009 Tri-County Electric Cooperative, St. Matthews, South Carolina
#    This file is part of COOPGIS.
#    COOPGIS is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#    COOPGIS is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#    You should have received a copy of the GNU General Public License
#    along with COOPGIS.  If not, see <http://www.gnu.org/licenses/>.

import os
import datetime
FTPFileName='/opt/coopgis/fromgps/anonymousftproot_OtherReadOnly/incomingftpallpermissions/Locations.csv'
import shutil

#************************BEGIN Add Include Files to Path************************
import sys
NeededPaths=['/opt/coopgis/djangoproject/include', '/opt/coopgis/djangoproject']
for path in NeededPaths:
    if(not path in sys.path):
        sys.path.append(path)
#************************END   Add Include Files to Path************************
from django.contrib.gis.geos import *
import os, time, psycopg2, datetime
#********************Setup psycopg2 and django section********************
PathDjangoRoot="/opt/coopgis/"
if(not PathDjangoRoot in sys.path):
    sys.path.append(PathDjangoRoot)
import djangoproject
from djangoproject.models import *
#********************Setup psycopg2 and django section********************

from django.template import Context, loader
from django.http import HttpResponse
from django import forms
import os
import datetime
import djangoproject.settings
import COOPGIS_Ajax

#*************************************************************************
#*************************************************************************
#{{RepeatingBlock}} is the repeating block placeholder, the # of times
#is defined within each Update function
#*************************************************************************
#*************************************************************************


def WriteAssemblyEditorStatus(String):  
    File=open(djangoproject.settings.COOPGISAssemblyEditorLogFileName, 'a')
    File.write(str(datetime.datetime.now()) + ':   ' + String + '\n')
    File.close()


def UpdateDynamicTemplates():
    UpdateAssemblyEditorTemplate()
    UpdateStakerAssemblyEditorTemplate()

def UpdateAssemblyEditorTemplate(NumberOfStationFormEntries, NumberOfSpanFormEntries, UserName=''):
    FileName='/opt/coopgis/djangoproject/templates/assemblyeditor' + UserName + '.html'
    ReplacementBlockList=[]
    for i in range(0, max(NumberOfStationFormEntries, NumberOfSpanFormEntries)):
        ReplacementBlockList.append(AssemblyEditorTemplateRepeatingBlockStation.replace('{{repeatnumber}}', str(i)))
        if(i < NumberOfSpanFormEntries):
            ReplacementBlockList.append(AssemblyEditorTemplateRepeatingBlockSpan.replace('{{repeatnumber}}', str(i)))
        ReplacementBlockList.append(AssemblyEditorTemplateRepeatingBlockEndOfRow)
    ReplacementBlockString=''.join(ReplacementBlockList)
    FinalTemplate=AssemblyEditorTemplate.replace('{{Repeating Block}}', ReplacementBlockString)
    FinalTemplate = FinalTemplate.replace('{{OpenLayersJavaScriptHeading}}', COOPGIS_Ajax.GetOpenLayersJavaScriptHeading())
    FinalTemplate = FinalTemplate.replace('{{OpenLayersJavaScript}}', COOPGIS_Ajax.GetOpenLayersJavaScript(OpenLayersJavaScriptHeading=FinalTemplate))
    #raise(Exception('Made it here'))
    try:
        os.remove(FileName)
    except OSError:
        pass
    TemplateFile=open(FileName, 'w')
    TemplateFile.write(FinalTemplate)
    TemplateFile.close()


def UpdateStakerAssemblyEditorTemplate(NumberOfStationFormEntries, NumberOfSpanFormEntries, UserName='', stakerWorkOrder=None):
    FileName='/opt/coopgis/djangoproject/templates/stakerassemblyeditor' + UserName + '.html'
    ReplacementBlockList=[]
    for i in range(0, max(NumberOfStationFormEntries, NumberOfSpanFormEntries)):
        ReplacementBlockList.append(StakerAssemblyEditorTemplateRepeatingBlockStation.replace('{{repeatnumber}}', str(i)))
        if(i < NumberOfSpanFormEntries):
            ReplacementBlockList.append(StakerAssemblyEditorTemplateRepeatingBlockSpan.replace('{{repeatnumber}}', str(i)))
        ReplacementBlockList.append(StakerAssemblyEditorTemplateRepeatingBlockEndOfRow)
    ReplacementBlockString=''.join(ReplacementBlockList)
    FinalTemplate=StakerAssemblyEditorTemplate.replace('{{Repeating Block}}', ReplacementBlockString)
    FinalTemplate = FinalTemplate.replace('{{OpenLayersJavaScriptHeading}}', COOPGIS_Ajax.GetOpenLayersJavaScriptHeading())
    FinalTemplate = FinalTemplate.replace('{{OpenLayersJavaScript}}', COOPGIS_Ajax.GetOpenLayersJavaScript(OpenLayersJavaScriptHeading=FinalTemplate))
    if(stakerWorkOrder):
        Longitude, Latitude, Zoom=stakerWorkOrder.GetCenterAndZoom()
        Longitude=str(Longitude)
        Latitude=str(Latitude)
        Zoom=str(Zoom)
    else:
        Longitude="-80.9"
        Latitude="33.7"
        Zoom="8"
    ZoomString="var lon = " + Longitude + "; var lat = " + Latitude + "; var zoom = " + Zoom + ";\n"
    FinalTemplate=FinalTemplate.replace('{{ZoomString}}', ZoomString)
    try:
        os.remove(FileName)
    except OSError:
        pass
    TemplateFile=open(FileName, 'w')
    TemplateFile.write(FinalTemplate)
    TemplateFile.close()

def UpdateCircuitAnalysisTemplate(NumberOfStationFormEntries, NumberOfSpanFormEntries, UserName=''):
    FileName='/opt/coopgis/djangoproject/templates/circuitanalysis' + UserName + '.html'
    ReplacementBlockList=[]
    for i in range(0, max(NumberOfStationFormEntries, NumberOfSpanFormEntries)):
        ReplacementBlockList.append(CircuitAnalysisTemplateRepeatingBlockStation.replace('{{repeatnumber}}', str(i)))
        if(i < NumberOfSpanFormEntries):
            ReplacementBlockList.append(CircuitAnalysisTemplateRepeatingBlockSpan.replace('{{repeatnumber}}', str(i)))
        ReplacementBlockList.append(CircuitAnalysisTemplateRepeatingBlockEndOfRow)
    ReplacementBlockString=''.join(ReplacementBlockList)
    FinalTemplate=CircuitAnalysisTemplate.replace('{{Repeating Block}}', ReplacementBlockString)
    FinalTemplate = FinalTemplate.replace('{{OpenLayersJavaScriptHeading}}', COOPGIS_Ajax.GetOpenLayersJavaScriptHeading())
    FinalTemplate = FinalTemplate.replace('{{OpenLayersJavaScript}}', COOPGIS_Ajax.GetOpenLayersJavaScript(OpenLayersJavaScriptHeading=FinalTemplate))
    try:
        os.remove(FileName)
    except OSError:
        pass
    TemplateFile=open(FileName, 'w')
    TemplateFile.write(FinalTemplate)
    TemplateFile.close()

def UpdateStakerQuickGenerateWorkOrderTemplate(NumberOfFormEntries, UserName=''):
    FileName='/opt/coopgis/djangoproject/templates/stakerquickgenerateworkorder' + UserName + '.html'
    ReplacementBlockList=[]
    for i in range(0, NumberOfFormEntries):
        ReplacementBlockList.append(StakerQuickGenerateWorkOrderRepeatingBlockAssembly.replace('{{repeatnumber}}', str(i)))
    ReplacementBlockString=''.join(ReplacementBlockList)
    FinalTemplate=StakerQuickGenerateWorkOrderTemplate.replace('{{Repeating Block}}', ReplacementBlockString)
    FinalTemplate = FinalTemplate.replace('{{OpenLayersJavaScriptHeading}}', COOPGIS_Ajax.GetOpenLayersJavaScriptHeading())
    FinalTemplate = FinalTemplate.replace('{{OpenLayersJavaScript}}', COOPGIS_Ajax.GetOpenLayersJavaScript(OpenLayersJavaScriptHeading=FinalTemplate))
    try:
        os.remove(FileName)
    except OSError:
        pass
    TemplateFile=open(FileName, 'w')
    TemplateFile.write(FinalTemplate)
    TemplateFile.close()

def UpdateInventoryCollectionTemplate(ShortcutList, UserName=''):
    FileName='/opt/coopgis/djangoproject/templates/inventorycollection' + UserName + '.html'
    BaseBlock=InventoryCollectionRepeatingBlockShortcut
    ShortcutWithAssemblyNameList=[]
    for i in ShortcutList:
        ShortcutWithAssemblyNameList.append(BaseBlock.replace('{{ShortcutAssemblyName}}', i))
    ShortcutWithAssemblyNameString=''.join(ShortcutWithAssemblyNameList)
    FinalTemplate=InventoryCollectionTemplate.replace('{{Repeating Block Shortcut}}', ShortcutWithAssemblyNameString)
    FinalTemplate = FinalTemplate.replace('{{OpenLayersJavaScriptHeading}}', COOPGIS_Ajax.GetOpenLayersJavaScriptHeading())
    FinalTemplate = FinalTemplate.replace('{{OpenLayersJavaScript}}', COOPGIS_Ajax.GetOpenLayersJavaScript(OpenLayersJavaScriptHeading=FinalTemplate))
    try:
        os.remove(FileName)
    except OSError:
        pass
    TemplateFile=open(FileName, 'w')
    TemplateFile.write(FinalTemplate)
    TemplateFile.close()

def UpdateSubstationEquipmentInspectionTemplate(UserName, substationEquipmentTemplate):
    FileName='/opt/coopgis/djangoproject/templates/substationequipmentinspection' + UserName + '.html'
    BaseBlock=InventoryCollectionRepeatingBlockShortcut
    FinalTemplate=BuildSubstationEquipmentInspectionTemplate(substationEquipmentTemplate)
    FinalTemplate = FinalTemplate.replace('{{OpenLayersJavaScriptHeading}}', COOPGIS_Ajax.GetOpenLayersJavaScriptHeading())
    FinalTemplate = FinalTemplate.replace('{{OpenLayersJavaScript}}', COOPGIS_Ajax.GetOpenLayersJavaScript(OpenLayersJavaScriptHeading=FinalTemplate))

    try:
        os.remove(FileName)
    except OSError:
        pass
    TemplateFile=open(FileName, 'w')
    TemplateFile.write(FinalTemplate)
    TemplateFile.close()

def UpdateOutdoorLightingSendToBillingTemplate(Conditions, UserName=''):
    FileName='/opt/coopgis/djangoproject/templates/outdoorlightingsendtobilling_' + UserName + '.html'
    ReplacementBlockList=[]
    for i in range(0, len(Conditions)):
        NoteList=ConditionMemberDescriptionHistory.objects.filter(Condition=Conditions[i]).order_by('-id')
        NoteListStringList=[]
        #NoteListStringList.append('<table>')
        NoteListStringList.append('<tr><td>User/Date </td><td>Description</td></tr>')

        for note in NoteList:
            if(note.CreateUserName):
                notename=str(note.CreateUserName)
            else:
                notename=''
            if(note.CreateDateTime):
                notecreatedatetime=str(note.CreateDateTime)[:10]
            else:
                notecreatedatetime=''

            NoteListStringList.append('<tr><td>' + notename + ':  ' + notecreatedatetime + '</td><td>{% autoescape on %}' + str(note.Description) + '{% endautoescape %}</td></tr>')
        ReplacementBlockList.append(OutdoorLightingSendToBillingTemplateRepeatingBlock.replace('{{repeatnumber}}', str(i)).replace('{{NoteListStringList}}', ''.join(NoteListStringList)))
    ReplacementBlockString=''.join(ReplacementBlockList)
    FinalTemplate=OutdoorLightingSendToBillingTemplate.replace('{{Repeating Block}}', ReplacementBlockString)
    try:
        os.remove(FileName)
    except OSError:
        pass
    TemplateFile=open(FileName, 'w')
    TemplateFile.write(FinalTemplate)
    TemplateFile.close()


OutdoorLightingSendToBillingTemplate="""
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<!--
#    Copyright 2010 Tri-County Electric Cooperative, St. Matthews, South Carolina
#    This file is part of COOPGIS.
#    COOPGIS is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#    COOPGIS is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#    You should have received a copy of the GNU General Public License
#    along with COOPGIS.  If not, see <http://www.gnu.org/licenses/>.
-->
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>{{GenericReportTitle}}</title>
    <style type="text/css">
        #inner {
            border: 1px solid black;
        }
        table.topalign td {
            vertical-align: top 
        } 
    </style>
</head>

<body>

<b>{{GenericReportTitle}}</b> &nbsp&nbsp&nbsp&nbsp <small><a href="/coopgis/">Main Menu</a></small><br>
{{LoginStatus}} 
<br>
<form method="post" action="">
<input type="submit"/><br>

<table class="topalign">
        <th>ID</th>
        <th>Update</th>
        <th>Send to<br> Billing</th>
        <th>Tag</th>
        <th>Map#</th>       
        <th>Meter#</th>
        <th>Meter Map#</th>
        <th>Idle</th>
        <th>Needs <br>Retire</th>
        <th>Rate</th>
        <th>Add'l Billable<br>Pole Count</th>
        <th>Owns Pole</th>
        <th>Owns Light</th>
        <th>Owned Count</th>
        <th>Description</th>
        <th>Description History<th>
    {{Repeating Block}}
</table>
</form>

<br><br>


</body>
</html>

"""


OutdoorLightingSendToBillingTemplateRepeatingBlock="""
<tr>
    <td>{{form.Conditionid{{repeatnumber}}}}</td>
    <td>{{form.UpdateIndicator{{repeatnumber}}}}</td>
    <td>{{form.SendToBillingIndicator{{repeatnumber}}}}</td>
    <td>{{form.TagNumber{{repeatnumber}}}}</td>
    <td>{{form.MapNumber{{repeatnumber}}}}</td>
    <td>{{form.MeterNumber{{repeatnumber}}}}</td>
    <td>{{form.MeterMapNumber{{repeatnumber}}}}</td>
    <td>{{form.IdleIndicator{{repeatnumber}}}}</td>
    <td>{{form.NeedsRetirementIndicator{{repeatnumber}}}}</td>
    <td>{{form.OutdoorLightRate{{repeatnumber}}}}</td>
    <td>{{form.OutdoorLightAdditionalBillingPoleCount{{repeatnumber}}}}</td>
    <td>{{form.CustomerOwnsPoleIndicator{{repeatnumber}}}}</td>
    <td>{{form.CustomerOwnsLightIndicator{{repeatnumber}}}}</td>
    <td>{{form.ConsumerOwnedLightCount{{repeatnumber}}}}</td>
    <td>{{form.ConditionDescription{{repeatnumber}}}}</td>
    <td>
        <div id="inner">
        <table>{{NoteListStringList}}</table>
        </div>
    </td>
</tr>
"""




def UpdateOutdoorLightingTemplate(NumberOfConditions, UserName=''):
    FileName='/opt/coopgis/djangoproject/templates/outdoorlighting' + UserName + '.html'
    ReplacementBlockList=[]
    for i in range(0, NumberOfConditions):
        ReplacementBlockList.append(OutdoorLightingTemplateRepeatingBlock.replace('{{repeatnumber}}', str(i)))
    ReplacementBlockString=''.join(ReplacementBlockList)
    FinalTemplate=OutdoorLightingTemplate.replace('{{Repeating Block}}', ReplacementBlockString)
    FinalTemplate = FinalTemplate.replace('{{OpenLayersJavaScriptHeading}}', COOPGIS_Ajax.GetOpenLayersJavaScriptHeading())
    FinalTemplate = FinalTemplate.replace('{{OpenLayersJavaScript}}', COOPGIS_Ajax.GetOpenLayersJavaScript(OpenLayersJavaScriptHeading=FinalTemplate))
    try:
        os.remove(FileName)
    except OSError:
        pass
    TemplateFile=open(FileName, 'w')
    TemplateFile.write(FinalTemplate)
    TemplateFile.close()

OutdoorLightingTemplate="""<!--
#    Copyright 2009, Tri-County Electric Cooperative, St. Matthews, South Carolina
#    This file is part of COOPGIS.
#    COOPGIS is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#    COOPGIS is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#    You should have received a copy of the GNU General Public License
#    along with COOPGIS.  If not, see <http://www.gnu.org/licenses/>.
**************************************************************************
THIS FILE WAS DYNAMICALLY GENERATED BY THE DYNAMIC TEMPLATE INCLUDE
MODIFICATIONS TO THIS FILE WILL BE PERIODICALLY OVERWRITTEN!!!!!
MODIFY THIS TEMPLATE IN THE DYNAMICTEMPLATE.PY FILE
**************************************************************************
-->

<html xmlns="http://www.w3.org/1999/xhtml">
  <head> 
    <style type="text/css">
        #map{
            width: 400px;
            height: 600px;
            border: 1px solid black;
            }
    </style>
    {{OpenLayersJavaScriptHeading}}
    <title>COOPGIS Outdoor Lighting</title>
  </head>

  <body onload="init()">
  <b>{{LoginStatus}}</b>   &nbsp&nbsp&nbsp&nbsp <small><a href="/coopgis/">Main Menu</a></small><br>
  <br>
  <table style = "width:100%" border = "1">
  <form method="post" action="">
  <col width = "400">
    <tr>
        <td valign="top" rowspan = "4">
          <div id="map">
            {{OpenLayersJavaScript}}
          </div>
        </td>
        <td valign = "top">
    	    <small>Map {{form.Map}} 
    	    Select Using GPS{{form.SelectGPSIndicator}} {{GPSStatus}}
            <input type="submit"/>
        </td>
    <tr>
        <td>
    	    <b>Selection</b><br>
            Station {{form.SelectStationid}}
            Tag {{form.SelectStationTagNumber}}
            RoadName {{form.SelectRoadName}}<br>
            MeterNumber {{form.SelectMeterNumber}}
            DCSINumber {{form.SelectDCSINumber}}<br>
            Assemblies at Station {{form.AssembliesAtSelectionStation}}
        </td>
    </tr>
    <tr>
        <td valign = "top">
            <table>
                {{Repeating Block}}
            </table>
        </td>
    </tr>
    <tr><td></td></tr>
  </table>
</form>
<br>
</ul>
</body>
</html>"""

OutdoorLightingTemplateRepeatingBlock="""
<tr>
    <td valign="top">
        <b>Update:</b>  {{form.UpdateIndicator{{repeatnumber}}}}  Delete {{form.DeletedIndicator{{repeatnumber}}}}<br>
        ID {{form.Conditionid{{repeatnumber}}}}<br>
        Station ID{{form.StationIdentifier{{repeatnumber}}}}<br>
        Tag# {{form.TagNumber{{repeatnumber}}}}<br>
        Map# &nbsp&nbsp&nbsp{{form.OutdoorLightMapNumber{{repeatnumber}}}} <br>
        Meter# {{form.OutdoorLightMeterNumber{{repeatnumber}}}} <br>
        MeterMap# {{form.OutdoorLightMeterMapNumber{{repeatnumber}}}}
    </td>
    <td valign="top">
        <b>Classification</b><br>
        Department {{form.ConditionDepartment{{repeatnumber}}}}<br>
        Immediate{{form.PriorityImmediateIndicator{{repeatnumber}}}} <br>
        ASAP{{form.PriorityASAPIndicator{{repeatnumber}}}} <br>
        Routine{{form.PriorityRoutineIndicator{{repeatnumber}}}}<br>
        Everything Fixed{{form.PriorityEverythingFixedMaintenanceOnlyIndicator{{repeatnumber}}}}<br>
        Everything OK{{form.PriorityEverythingOkInspectionOnlyIndicator{{repeatnumber}}}}<br>
        Vegetation Needs Attention{{form.PriorityVegetationNeedsAttentionIndicator{{repeatnumber}}}}<br>
    </td>
    <td valign="top">
        <b>Inspection</b><br>
        Pole &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp{{form.PoleConditionStatus{{repeatnumber}}}}<br>
        GuyAnchor {{form.GuyAnchorConditionStatus{{repeatnumber}}}}<br>
        Insulator {{form.InsulatorConditionStatus{{repeatnumber}}}}<br>
        Conductor {{form.ConductorConditionStatus{{repeatnumber}}}}<br>
        RightOfWay{{form.RightOfWayConditionStatus{{repeatnumber}}}}<br>
        PadMount {{form.PadMountConditionStatus{{repeatnumber}}}}<br>
        Vault &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp{{form.VaultConditionStatus{{repeatnumber}}}}<br>
        RiserCable {{form.RiserCableConditionStatus{{repeatnumber}}}}
    </td>
    <td valign="top">
        <b>OutdoorLight</b><br>
        Outdoor Lighting {{form.PriorityOutdoorLightingConversionIndicator{{repeatnumber}}}}<br>
        Needs Retirement {{form.NeedsRetirementIndicator{{repeatnumber}}}}<br>
        Idle In Field {{form.OutdoorLightIdleIndicator{{repeatnumber}}}}<br>
        Number of Lights {{form.OutdoorLightConsumerOwnedLightCount{{repeatnumber}}}}<br>
        Rate {{form.OutdoorLightRate{{repeatnumber}}}}<br>
        Problem Description {{form.OutdoorLightProblemCode{{repeatnumber}}}}<br>
        Add'l Billable Pole Count {{form.OutdoorLightAdditionalBillingPoleCount{{repeatnumber}}}}<br>
        Member Owns Pole {{form.OutdoorLightCustomerOwnsPoleIndicator{{repeatnumber}}}}<br>
        Member Owns Light {{form.OutdoorLightCustomerOwnsLightIndicator{{repeatnumber}}}}<br>
        <br>
        Description<br>
        {{form.ConditionMemberDescription{{repeatnumber}}}}<br>
        Office Status {{form.OutdoorLightBillingWorkStartedNotificationString{{repeatnumber}}}}
    </td>
    <td valign="top">
        <b>Work Order</b><br>
        Order {{form.WorkOrderNumber{{repeatnumber}}}}<br>
        Performed By {{form.WorkPerformedBy{{repeatnumber}}}}<br>
        Date {{form.WorkDate{{repeatnumber}}}}<br>
        Hours {{form.WorkHours{{repeatnumber}}}}<br>
        Remarks {{form.WorkRemarks{{repeatnumber}}}}<br>
        Complete {{form.WorkCompletedIndicator{{repeatnumber}}}}<br>
        Not Complete {{form.WorkNotCompletedIndicator{{repeatnumber}}}}<br>
        <small>If not, describe:</small><br>
        {{form.WorkNotCompletedDescription{{repeatnumber}}}}<br>
        <br>
        Foreman {{form.WorkForeman{{repeatnumber}}}}<br>
        Signed Off {{form.WorkForemanSignoffIndicator{{repeatnumber}}}}  Date {{form.WorkForemanSignoffDateTime{{repeatnumber}}}}<br>
        <br><br>
    </td>
</tr>
    

"""


    

InventoryCollectionRepeatingBlockShortcut="""
    {{ShortcutAssemblyName}}{{form.StationAssemblyShortcut{{ShortcutAssemblyName}}CreateIndicator}}
    Qt{{form.StationAssemblyShortcut{{ShortcutAssemblyName}}NumberOfCopies}}
    Cir{{form.StationAssemblyShortcut{{ShortcutAssemblyName}}CircuitNumber}}
    Pri{{form.StationAssemblyShortcut{{ShortcutAssemblyName}}PrimaryIndicator}}
    Sec{{form.StationAssemblyShortcut{{ShortcutAssemblyName}}SecondaryIndicator}}
    Ser{{form.StationAssemblyShortcut{{ShortcutAssemblyName}}ServiceIndicator}}<br>
"""


AssemblyEditorTemplateRepeatingBlockStation="""
        <tr><td valign="top">&nbsp</td><td valign="top">&nbsp</td></tr>
        <tr><td valign="top"><small>Unit:  {{form.StationAssemblyCompatibleUnit{{repeatnumber}}}}<br>  
                        Update:  {{form.StationAssemblyUpdateIndicator{{repeatnumber}}}}
			Del:  {{form.StationAssemblyDeleteIndicator{{repeatnumber}}}}
                        ID {{form.StationAssemblyID{{repeatnumber}}}}<br>
                        Cir#{{form.StationAssemblyCircuitNumber{{repeatnumber}}}} 
                        A{{form.StationAssemblyPhaseAIndicator{{repeatnumber}}}} 
                        B{{form.StationAssemblyPhaseBIndicator{{repeatnumber}}}}
                        C{{form.StationAssemblyPhaseCIndicator{{repeatnumber}}}}
                        N{{form.StationAssemblyPhaseNeutralIndicator{{repeatnumber}}}}
                        I{{form.StationAssemblyIdleIndicator{{repeatnumber}}}}<br>
                        Pri: {{form.StationAssemblyPrimaryIndicator{{repeatnumber}}}}
                        Sec: {{form.StationAssemblySecondaryIndicator{{repeatnumber}}}}
                        Ser: {{form.StationAssemblyServiceIndicator{{repeatnumber}}}}<br>
                        Tag{{form.StationAssemblyTagNumber{{repeatnumber}}}}
                        Lgt{{form.StationAssemblyPoleLightIndicator{{repeatnumber}}}}
                        Mtr{{form.StationAssemblyPoleMeterIndicator{{repeatnumber}}}}
                        Stub{{form.StationAssemblyPoleStubIndicator{{repeatnumber}}}}<br>
                        <small>Mtr{{form.StationAssemblyMeterNumber{{repeatnumber}}}}
                        DCSI{{form.StationAssemblyMeterDCSINumber{{repeatnumber}}}} 
                        Map{{form.StationAssemblyMapNumber{{repeatnumber}}}}
                        OldMap{{form.StationAssemblyOldMapNumber{{repeatnumber}}}}
                        MOP{{form.StationAssemblyMeterOnPoleIndicator{{repeatnumber}}}}<br>
                        Type{{form.StationAssemblyMeterServiceType{{repeatnumber}}}}
                        Frm{{form.StationAssemblyMeterForm{{repeatnumber}}}}<br>
                        <small>
                        Owner{{form.StationAssemblyOwner{{repeatnumber}}}}
                        Manu{{form.StationAssemblyManufacturer{{repeatnumber}}}}
                        Op{{form.StationAssemblyOpenIndicator{{repeatnumber}}}}<br>
                        </small>
                        Serial{{form.StationAssemblySerialNumber{{repeatnumber}}}}
                        Year{{form.StationAssemblyPutIntoServiceDateYear{{repeatnumber}}}}
                        Address{{form.StationAssemblyPhysicalAddress{{repeatnumber}}}}<br>
                        Rotation{{form.StationAssemblyRotation{{repeatnumber}}}} Trans. Bank{{form.StationAssemblyTransformerBank{{repeatnumber}}}}<br>
                        Install{{form.StationAssemblyInstallStatus{{repeatnumber}}}}Staker{{form.StationAssemblyStakerWorkOrderid{{repeatnumber}}}}<br>
                        </small> </small>  </td> """

AssemblyEditorTemplateRepeatingBlockSpan="""
                        <td valign="top"><small>
                        Unit:  {{form.SpanAssemblyCompatibleUnit{{repeatnumber}}}}<br>
                        Update:  {{form.SpanAssemblyUpdateIndicator{{repeatnumber}}}}
			Del:  {{form.SpanAssemblyDeleteIndicator{{repeatnumber}}}}
                        ID {{form.SpanAssemblyID{{repeatnumber}}}} <br>
                        Cir#{{form.SpanAssemblyCircuitNumber{{repeatnumber}}}} 
                        A{{form.SpanAssemblyPhaseAIndicator{{repeatnumber}}}} 
                        B{{form.SpanAssemblyPhaseBIndicator{{repeatnumber}}}}
                        C{{form.SpanAssemblyPhaseCIndicator{{repeatnumber}}}}
                        N{{form.SpanAssemblyPhaseNeutralIndicator{{repeatnumber}}}}
                        I{{form.SpanAssemblyIdleIndicator{{repeatnumber}}}}<br>
                        Pri: {{form.SpanAssemblyPrimaryIndicator{{repeatnumber}}}}
                        Sec: {{form.SpanAssemblySecondaryIndicator{{repeatnumber}}}}
                        Ser: {{form.SpanAssemblyServiceIndicator{{repeatnumber}}}} <br></small></td>"""

AssemblyEditorTemplateRepeatingBlockEndOfRow="""</tr>"""





StakerAssemblyEditorTemplateRepeatingBlockStation="""
       <tr><td valign="top"><small>Unit:  {{form.StationAssemblyCompatibleUnit{{repeatnumber}}}}<br>  
                        Update:  {{form.StationAssemblyUpdateIndicator{{repeatnumber}}}}
			Del:  {{form.StationAssemblyDeleteIndicator{{repeatnumber}}}}
                        ID {{form.StationAssemblyID{{repeatnumber}}}}<br>
                        Cir#{{form.StationAssemblyCircuitNumber{{repeatnumber}}}} 
                        A{{form.StationAssemblyPhaseAIndicator{{repeatnumber}}}} 
                        B{{form.StationAssemblyPhaseBIndicator{{repeatnumber}}}}
                        C{{form.StationAssemblyPhaseCIndicator{{repeatnumber}}}}
                        N{{form.StationAssemblyPhaseNeutralIndicator{{repeatnumber}}}}
                        I{{form.StationAssemblyIdleIndicator{{repeatnumber}}}}<br>
                        Pri: {{form.StationAssemblyPrimaryIndicator{{repeatnumber}}}}
                        Sec: {{form.StationAssemblySecondaryIndicator{{repeatnumber}}}}
                        Ser: {{form.StationAssemblyServiceIndicator{{repeatnumber}}}}<br>
                        Tag{{form.StationAssemblyTagNumber{{repeatnumber}}}}
                        Lgt{{form.StationAssemblyPoleLightIndicator{{repeatnumber}}}}
                        Mtr{{form.StationAssemblyPoleMeterIndicator{{repeatnumber}}}}
                        Stub{{form.StationAssemblyPoleStubIndicator{{repeatnumber}}}}<br>
                        <small>Mtr{{form.StationAssemblyMeterNumber{{repeatnumber}}}}
                        DCSI{{form.StationAssemblyMeterDCSINumber{{repeatnumber}}}} 
                        Map{{form.StationAssemblyMapNumber{{repeatnumber}}}}
                        OldMap{{form.StationAssemblyOldMapNumber{{repeatnumber}}}}
                        MOP{{form.StationAssemblyMeterOnPoleIndicator{{repeatnumber}}}}<br>
                        Type{{form.StationAssemblyMeterServiceType{{repeatnumber}}}}
                        Frm{{form.StationAssemblyMeterForm{{repeatnumber}}}}<br>
                        <small>
                        Owner{{form.StationAssemblyOwner{{repeatnumber}}}}
                        Manu{{form.StationAssemblyManufacturer{{repeatnumber}}}}
                        Op{{form.StationAssemblyOpenIndicator{{repeatnumber}}}}<br>
                        </small>
                        Serial{{form.StationAssemblySerialNumber{{repeatnumber}}}}
                        Year{{form.StationAssemblyPutIntoServiceDateYear{{repeatnumber}}}}<br>
                        Address{{form.StationAssemblyPhysicalAddress{{repeatnumber}}}} <small>Recipe</small>{{form.StationAssemblyStakerRecipeNumber{{repeatnumber}}}}<br>
                        Install{{form.StationAssemblyInstallStatus{{repeatnumber}}}}  Copies {{form.StationAssemblyNumberOfCopies{{repeatnumber}}}}<br>
                        Staker{{form.StationAssemblyStakerWorkOrderid{{repeatnumber}}}}
                        Update{{form.StationAssemblyStakerWorkOrderChangeToCurrentIndicator{{repeatnumber}}}}
                        None{{form.StationAssemblyStakerWorkOrderDisassociateIndicator{{repeatnumber}}}}<br>
                        Rotation{{form.StationAssemblyRotation{{repeatnumber}}}}<br>
                   <br>
                        </small> </small>  </td>""" 

StakerAssemblyEditorTemplateRepeatingBlockSpan="""
                        <td valign="top"><small>
                        Unit:  {{form.SpanAssemblyCompatibleUnit{{repeatnumber}}}}<br>
                        Update:  {{form.SpanAssemblyUpdateIndicator{{repeatnumber}}}}
			Del:  {{form.SpanAssemblyDeleteIndicator{{repeatnumber}}}}
                        ID {{form.SpanAssemblyID{{repeatnumber}}}} <br>
                        Cir#{{form.SpanAssemblyCircuitNumber{{repeatnumber}}}} 
                        A{{form.SpanAssemblyPhaseAIndicator{{repeatnumber}}}} 
                        B{{form.SpanAssemblyPhaseBIndicator{{repeatnumber}}}}
                        C{{form.SpanAssemblyPhaseCIndicator{{repeatnumber}}}}
                        N{{form.SpanAssemblyPhaseNeutralIndicator{{repeatnumber}}}}
                        I{{form.SpanAssemblyIdleIndicator{{repeatnumber}}}}<br>
                        Pri: {{form.SpanAssemblyPrimaryIndicator{{repeatnumber}}}}
                        Sec: {{form.SpanAssemblySecondaryIndicator{{repeatnumber}}}}
                        Ser: {{form.SpanAssemblyServiceIndicator{{repeatnumber}}}} <br>
                        Install{{form.SpanAssemblyInstallStatus{{repeatnumber}}}}  Copies {{form.SpanAssemblyNumberOfCopies{{repeatnumber}}}}<br>
                        <small>Staker{{form.SpanAssemblyStakerWorkOrderid{{repeatnumber}}}}
                        Update{{form.SpanAssemblyStakerWorkOrderChangeToCurrentIndicator{{repeatnumber}}}}
                        None{{form.SpanAssemblyStakerWorkOrderDisassociateIndicator{{repeatnumber}}}}</small><br>
                        <small>Recipe</small>{{form.SpanAssemblyStakerRecipeNumber{{repeatnumber}}}}
                        </small></td>""" 
StakerAssemblyEditorTemplateRepeatingBlockEndOfRow="""</tr>"""


CircuitAnalysisTemplateRepeatingBlockStation="""
        <tr><td valign="top"><small>
                        {{form.StationAssemblyCompatibleUnit{{repeatnumber}}}}<br>  
                        Bypass: {{form.StationAssemblyBypassAssembly{{repeatnumber}}}}<br>
                        Update:  {{form.StationAssemblyUpdateCircuitIndicator{{repeatnumber}}}}
		        ID {{form.StationAssemblyID{{repeatnumber}}}}<br>
                        Cir#{{form.StationAssemblyCircuitNumber{{repeatnumber}}}} 
                        A{{form.StationAssemblyPhaseAIndicator{{repeatnumber}}}} 
                        B{{form.StationAssemblyPhaseBIndicator{{repeatnumber}}}}
                        C{{form.StationAssemblyPhaseCIndicator{{repeatnumber}}}}
                        N{{form.StationAssemblyPhaseNeutralIndicator{{repeatnumber}}}}<br>
                        Op{{form.StationAssemblyOpenIndicator{{repeatnumber}}}} Transformer CutOut {{form.StationAssemblyTransformerCutOutIndicator{{repeatnumber}}}}<br>
                        Bypass: {{form.StationAssemblyBypassIndicator{{repeatnumber}}}}
                        {% if form.StationAssemblyProtectingAdd{{repeatnumber}} %}
                            Pro Span Add {{form.StationAssemblyProtectingAdd{{repeatnumber}}}} <br>
                            Pro Span Remove {{form.StationAssemblyProtectingRemove{{repeatnumber}}}}<br>
                        {% endif %}
                        </small> </small>  </td> """
CircuitAnalysisTemplateRepeatingBlockSpan="""
                        <td valign="top"><small>
                        {{form.SpanAssemblyCompatibleUnit{{repeatnumber}}}}<br>  Update:  {{form.SpanAssemblyUpdateIndicator{{repeatnumber}}}}
                        ID {{form.SpanAssemblyID{{repeatnumber}}}} <br>
                        Cir#{{form.SpanAssemblyCircuitNumber{{repeatnumber}}}} 
                        A{{form.SpanAssemblyPhaseAIndicator{{repeatnumber}}}} 
                        B{{form.SpanAssemblyPhaseBIndicator{{repeatnumber}}}}
                        C{{form.SpanAssemblyPhaseCIndicator{{repeatnumber}}}}
                        N{{form.SpanAssemblyPhaseNeutralIndicator{{repeatnumber}}}}<br></small></td></tr>
        <tr><td valign="top">&nbsp</td><td valign="top">&nbsp</td>"""
CircuitAnalysisTemplateRepeatingBlockEndOfRow="""</tr>"""


StakerQuickGenerateWorkOrderRepeatingBlockAssembly="""
        <tr><td>{{form.StakerWorkOrderid{{repeatnumber}}}} &nbsp&nbsp Tag {{form.TagNumber{{repeatnumber}}}}</td>
            <td>{{form.CompatibleUnit{{repeatnumber}}}}</td>
            <td>{{form.InstallStatus{{repeatnumber}}}}</td>
            <td>{{form.Stationid{{repeatnumber}}}}</td>
            <td>{{form.Spanid{{repeatnumber}}}}</td>
            <td>{{form.DisassociateIndicator{{repeatnumber}}}}</td>
            <td>{{form.Assemblyid{{repeatnumber}}}}</td>
        </tr>"""

AssemblyEditorTemplate="""<!--
#    Copyright 2008, 2009, 2010, 2011, 2012 Tri-County Electric Cooperative, St. Matthews, South Carolina
#    This file is part of COOPGIS.
#    COOPGIS is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#    COOPGIS is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#    You should have received a copy of the GNU General Public License
#    along with COOPGIS.  If not, see <http://www.gnu.org/licenses/>.
**************************************************************************
THIS FILE WAS DYNAMICALLY GENERATED BY THE DYNAMIC TEMPLATE INCLUDE
MODIFICATIONS TO THIS FILE WILL BE PERIODICALLY OVERWRITTEN!!!!!
MODIFY THIS TEMPLATE IN THE DYNAMICTEMPLATE.PY FILE
**************************************************************************
-->

<html xmlns="http://www.w3.org/1999/xhtml">
  <head> 
    <style type="text/css">
        #map {
            width: 750px;
            height: 600px;
            border: 1px solid black;
        }
    </style>
{{OpenLayersJavaScriptHeading}}
 



    <title>COOPGIS Assembly Editor</title>
  </head>
  <body>
<b>{{LoginStatus}}</b>   &nbsp&nbsp&nbsp&nbsp <small><a href="/coopgis/">Main Menu</a></small><br>
<br>

<table width="100%">
<form method="post" action="">
<COLGROUP span="400" width="600">

<tr><td valign="top"><div id="map">
{{OpenLayersJavaScript}}

</div><br>

<table width="75%">
<tr>
<td valign=top><h4>Nearby Span Information</h4><small>
	{% for line in SpanAssemblyList %}
	{{line}}<br>
	{% endfor %}
</small>
</td>
<td valign=top><h4>Nearby Station Information</h4><small>
	{% for line in StationAssemblyList %}
	 {{line}}<br>
	{% endfor %}
</small><td><br></tr>
</table>
</td>
<td valign="top" width="50%">
         <small>Map {{form.Map}} &nbsp&nbsp&nbsp&nbsp<input type="submit"/><br>
         Select Using GPS{{form.SelectGPSIndicator}} {{GPSStatus}}<br>
</colgroup>
<table> <tr><th>Station</th><th>Span</th></tr>
	<tr><td><small>ID{{form.SelectStationid}}Tag{{form.SelectStationTagNumber}}New{{form.CreateStationIndicator}}<br>
        Del:{{form.DeleteStationIndicator}}
        Mv:{{form.MoveStationGPSIndicator}}N:{{form.MoveStationNorth}}E:{{form.MoveStationEast}}<br>
        Note:{{form.StationComment}} Update:{{form.UpdateStationCommentIndicator}}<br></td>
        <td><small>ID{{form.SelectSpanid}} Far/'T'ag{{form.SpanFarStation}} <br>
        New{{form.CreateSpanIndicator}} 
        Del{{form.DeleteSpanIndicator}}Joint Trench{{form.SpanJointTrenchIndicator}}<br>   
        Nt{{form.SpanComment}} Tap{{form.SpanTapIndicator}} Upd{{form.UpdateSpanCommentIndicator}}<br>
        </small> </td></tr>
        {% if ServerIndicator %}
        <tr><td><small>Delete URD Marker {{form.RunDeleteURDMarkerStationIndicator}}</small></td><td><small>&nbsp</small></td></tr>
        {% endif %}
        <tr><td><small>Trans. Bank {{form.StationTransformerBank}}</small></td></tr>
        <tr><td><table>
        {% for transformerBank in TransformerBanks %}
            <tr><td><small>{{transformerBank.id}}</small></td><td><small>{{transformerBank.TransformerBankType.Name}}</small></td><td><small>{{transformerBank.TransformerBank.Station.id}}</small></td></tr>
        {% endfor %} 
        </table></td></tr>
        <small><small><small>{{GPSStatus2}}{{GPSStatus3}}</small></small></small>

        {{Repeating Block}}


</table>
</td></tr>
</table>
</form>
<br>
View of Last Submitted Map  <br>
</ul>
  </body>
</html>"""



StakerAssemblyEditorTemplate="""
<!--
#    Copyright 2008, 2009 Tri-County Electric Cooperative, St. Matthews, South Carolina
#    This file is part of COOPGIS.
#    COOPGIS is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#    COOPGIS is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#    You should have received a copy of the GNU General Public License
#    along with COOPGIS.  If not, see <http://www.gnu.org/licenses/>.
**************************************************************************
THIS FILE WAS DYNAMICALLY GENERATED BY THE DYNAMIC TEMPLATE INCLUDE
MODIFICATIONS TO THIS FILE WILL BE PERIODICALLY OVERWRITTEN!!!!!
MODIFY THIS TEMPLATE IN THE TEMPLATE DYNAMICTEMPLATE.PY FILE
**************************************************************************
-->

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <style type="text/css">
        #map {
            width: 750px;
            height: 600px;
            border: 1px solid black;
        }
    </style>
{{OpenLayersJavaScriptHeading}}
    <title>COOPGIS Staker Assembly Editor</title>
  </head>
  <body onload="init()">
<b>{{LoginStatus}}</b>   &nbsp&nbsp&nbsp&nbsp <small><a href="/coopgis/staker/">Staker Main Menu</a></small>&nbsp&nbsp&nbsp&nbsp&nbsp<b>Staker {{StakerWorkOrderMessage}}</b><br>
<br>
<table>
<form method="post" action="">
<tr><td valign="top"><div id="map">
{{OpenLayersJavaScript}}
</div>
<br>
<pre>{{SpanAngleTable}}</pre>
<pre>{{StakerRecipeReport}}</pre>
<br>
{% if ShowSummaryIndicator %} 
    <table>
    <tr><td valign="top"><small><small><small>ID</small></small></small></td>
        <td valign="top"><small><small><small>H/C</small></small></small></td>
        <td valign="top"><small><small><small>Pri_id</small></small></small></td>
        <td valign="top"><small><small><small>Spanid</small></small></small></td>
	<td valign="top"><small><small><small>Cond</small></small></small></td>
	<td valign="top"><small><small><small>Unit</small></small></small></td>
        <td valign="top"><small><small><small>Trans</small></small></small></td>
        <td valign="top"><small><small><small>Misc</small></small></small></td>
        <td valign="top"><small><small><small>Grd</small></small></small></td>
        <td valign="top"><small><small><small>Guy</small></small></small></td>
        <td valign="top"><small><small><small>Anchor</small></small></small></td>
        <td valign="top"><small><small><small>Sec</small></small></small></td>
        <td valign="top"><small><small><small>ID</small></small></small></td>
        <td valign="top"><small><small><small>Cond</small></small></small></td>
        <td valign="top"><small><small><small>Unit</small></small></small></td>
        <td valign="top"><small><small><small>Comments</small></small></small></td></tr>
    {% for row in StakerWorkOrderSummary %}
        <tr>
        {% for cell in row %}
            <td valign="top"><small><small><small>{{cell}}</small></small></small></td>
        {% endfor %}
        </tr>
    {% endfor %}
    </table>
{% endif %}


<td valign="top">
         <small>Map {{form.Map}} &nbsp&nbsp&nbsp&nbsp<input type="submit"/><br>
         Select Using GPS{{form.SelectGPSIndicator}} {{GPSStatus}} &nbsp&nbsp&nbsp&nbsp Show Summary {{form.ShowSummaryIndicator}} &nbsp&nbsp&nbsp Recipe Report {{form.StakerRecipeReportIndicator}} <br>
	 Previous:   Station{{form.PreviousStationid}} Span{{form.PreviousSpanid}} Use {{form.PreviousSelectionIndicator}}
<table> <tr><th>Station</th><th>Span</th></tr>
	<tr valign="top"><td><small>ID{{form.SelectStationid}}Tag{{form.SelectStationTagNumber}}New{{form.CreateStationIndicator}}<br>
        Del:{{form.DeleteStationIndicator}}
        Mv:{{form.MoveStationGPSIndicator}}N:{{form.MoveStationNorth}}E:{{form.MoveStationEast}}<br>
        Note:{{form.StationComment}} Update:{{form.UpdateStationCommentIndicator}}<br></td>
        <td><small>ID{{form.SelectSpanid}} Far/'T'ag{{form.SpanFarStation}}<br>
        New{{form.CreateSpanIndicator}} 
        Del{{form.DeleteSpanIndicator}}Joint Trench{{form.SpanJointTrenchIndicator}}<br>   
        Note:{{form.SpanComment}}Update:{{form.UpdateSpanCommentIndicator}}<br>
        Tap{{form.SpanTapIndicator}} StakerStopTrace{{form.StakerStopTraceIndicator}}
        </small> </td></tr>
        <tr><td>&nbsp</td><td><small>Split Span:  {{form.SplitSpanIndicator}}</small></td></br>
        <small><small><small>{{GPSStatus2}}</small></small></small>
        <tr><td valign="top">&nbsp</td><td valign="top">&nbsp</td></tr>
        {{Repeating Block}}
</table>
</form>
</ul>
  </body>
</html>

"""




CircuitAnalysisTemplate="""
<!--
#    Copyright 2008, 2009 Tri-County Electric Cooperative, St. Matthews, South Carolina
#    This file is part of COOPGIS.
#    COOPGIS is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#    COOPGIS is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#    You should have received a copy of the GNU General Public License
#    along with COOPGIS.  If not, see <http://www.gnu.org/licenses/>.
**************************************************************************
THIS FILE WAS DYNAMICALLY GENERATED BY THE DYNAMIC TEMPLATE INCLUDE
MODIFICATIONS TO THIS FILE WILL BE PERIODICALLY OVERWRITTEN!!!!!
MODIFY THIS TEMPLATE IN THE TEMPLATE DYNAMICTEMPLATE.PY FILE
**************************************************************************
-->

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <style type="text/css">
        #map {
            width: 750px;
            height: 600px;
            border: 1px solid black;
        }
    </style>
{{OpenLayersJavaScriptHeading}}

    <title>COOPGIS Circuit Analysis</title>
  </head>
  <body onload="init()">
<b>{{LoginStatus}}</b>   &nbsp&nbsp&nbsp&nbsp <small><a href="/coopgis/">Main Menu</a></small><br>
<br>
<table>
<form method="post" action="">
<tr><td valign="top"><div id="map">

{{OpenLayersJavaScript}}

</div></td>
<td valign="top">
         <small>Map {{form.Map}} &nbsp&nbsp&nbsp&nbsp<input type="submit"/><br>
         Select Using GPS{{form.SelectGPSIndicator}} {{GPSStatus}}<br>
         <br> 
         Trace Circuit{{form.TraceCircuitNumber}} {{TraceMessage}}<br><br>
         <b>GeoTrace{{form.GeoTraceIndicator}}</b> &nbsp&nbsp <br>
         Start Station {{form.GeoTraceStartStationid}} 
         Stop Spans {{form.GeoTraceSpanidsToStopAt}}<br>
         'It is my circuit fault.' to change:  {{form.GeoTraceConfirmChangeCircuit}}<br>
         From Circuit <small>(9999 for all):</small>{{form.GeoTraceFromCircuitNumber}} <br>
         To Circuit: {{form.GeoTraceToCircuitNumber}}<br>
         'It is my compatible unit fault.' to change:  {{form.GeoTraceConfirmChangeCompatibleUnit}}<br>

         From:  {{form.GeoTraceCompatibleUnitFrom}}<br>
         To:  {{form.GeoTraceCompatibleUnitTo}}<br>

         'It is my phase fault.' to change:  {{form.GeoTraceConfirmChangePhase}}<br>
         From:  None to:  {{form.GeoTracePhaseNoneTo}}<br>
         From:  A  to:   {{form.GeoTracePhaseATo}}<br>
         From:  B  to:   {{form.GeoTracePhaseBTo}}<br>
         From:  C  to:   {{form.GeoTracePhaseCTo}}<br>
         From:  N  to:   {{form.GeoTracePhaseNTo}}<br>
         <br>
         <br>	
<table> <tr><th>Station</th><th>Span</th></tr>
	<tr><td><small>ID{{form.SelectStationid}}Tag{{form.SelectStationTagNumber}}<br>
        Note:{{form.StationComment}} Update:{{form.UpdateStationCommentIndicator}}<br></td>
        <td><small>ID{{form.SelectSpanid}}<br>   
        Note: {{form.SpanComment}} Update: {{form.UpdateSpanCommentIndicator}}<br>
        </small> </td></tr>

        <tr><td valign="top">&nbsp</td><td valign="top">&nbsp</td></tr>
        {{Repeating Block}}
</table>
</td></tr></table>
</form>
<br>
View of Last Submitted Map  <br>
</ul>
  </body>
</html>
"""


StakerQuickGenerateWorkOrderTemplate="""
<!--
#    Copyright 2009 Tri-County Electric Cooperative, St. Matthews, South Carolina
#    This file is part of COOPGIS.
#    COOPGIS is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#    COOPGIS is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#    You should have received a copy of the GNU General Public License
#    along with COOPGIS.  If not, see <http://www.gnu.org/licenses/>.
**************************************************************************
THIS FILE WAS DYNAMICALLY GENERATED BY THE DYNAMIC TEMPLATE INCLUDE
MODIFICATIONS TO THIS FILE WILL BE PERIODICALLY OVERWRITTEN!!!!!
MODIFY THIS TEMPLATE IN THE TEMPLATE DYNAMICTEMPLATE.PY FILE
**************************************************************************
-->

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <style type="text/css">
        #map {
            width: 800px;
            height: 600px;
            border: 1px solid black;
        }
    </style>
    {{OpenLayersJavaScriptHeading}}
    <title>COOPGIS Staker Quick Generate Work Order</title>
</head>
<body>
<b>{{LoginStatus}}</b>   &nbsp&nbsp&nbsp&nbsp <small><a href="/coopgis/staker/">Staker Main Menu</a></small><br>

<h4>Staker Quick Generate Report for id:  {{StakerWorkOrderid}}  {{StakerWorkOrderName}}</h4>
<br>
<form method="post" action="">
<table>
    <tr>
        <td>
            <div id="map">{{OpenLayersJavaScript|safe}}</div>
        </td>
        <td valign="top">
            <table>
            <tr><td>Map:  {{form.Map}}</td><td><input type="submit" /></td></tr>
            <tr><td>Delete Polygon</td><td>{{form.DeletePolygonIndicator}}</td></tr>
            <tr><td>WKT: {{form.WKTPolygon}}</td><td>&nbsp</td></tr>
            <tr><td>Work Order #</td><td>Assembly Name</td><td>Install Status</td><td>Station</td><td>Span</td><td>Disassociate</td><td>Assembly</td></tr>
            {{Repeating Block}}
            </table>
        </td>
    </tr>
</table>
</form>
</body>
</html>
"""






InventoryCollectionRepeatingBlockShorcut="""
    {{ShortcutName}}{{form.StationAssemblyShortcut{{ShortcutAssemblyName}}CreateIndicator}}
    Qt{{form.StationAssemblyShortcut{{ShortcutAssemblyName}}NumberOfCopies}}
    Cir{{form.StationAssemblyShortcut{{ShortcutAssemblyName}}CircuitNumber}}
    Pri{{form.StationAssemblyShortcut{{ShortcutAssemblyName}}PrimaryIndicator}}
    Sec{{form.StationAssemblyShortcut{{ShortcutAssemblyName}}SecondaryIndicator}}
    Ser{{form.StationAssemblyShortcut{{ShortcutAssemblyName}}ServiceIndicator}}<br>
"""

InventoryCollectionTemplate="""
<!--
#    Copyright 2008, 2009 Tri-County Electric Cooperative, St. Matthews, South Carolina
#    This file is part of COOPGIS.
#    COOPGIS is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#    COOPGIS is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#    You should have received a copy of the GNU General Public License
#    along with COOPGIS.  If not, see <http://www.gnu.org/licenses/>.
-->

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <style type="text/css">
        #map {
            width: 600px;
            height: 500px;
            border: 1px solid black;
        }
    </style>
{{OpenLayersJavaScriptHeading}}

    <title>COOPGIS Inventory Collection</title>
  </head>
  <body onload="init()">
<b>{{LoginStatus}}</b> &nbsp&nbsp&nbsp&nbsp <small><a href="/coopgis/">Main Menu</a></small>
 <table>
<td>

<form method="post" action="">

	<table width="600"><tr><td valign=top width="300"><small><b>Station:</b>  {{ form.SelectStationid }} Tag#:  {{ form.SelectStationTagNumber }}<br>
		        &nbsp&nbsp&nbsp&nbsp New:   {{form.CreateStationIndicator}} 
                       
                       Del:  {{form.DeleteStationIndicator}}
                       Retry GPS:  {{form.MoveStationGPSIndicator}}<br>
                       {{GPSStatus}}<br>  

                        &nbsp&nbsp&nbsp&nbsp Comment{{form.StationComment}} Update{{form.UpdateStationCommentIndicator}}<br>
	
		        &nbsp&nbsp&nbsp&nbsp North:  {{form.MoveStationNorth}}  East {{form.MoveStationEast}}<br> </small>
	<small>
        <b>Pole Treatment:</b>  {{form.PoleTreatmentType}}<br>
        &nbsp&nbsp&nbsp&nbsp Company:  {{form.PoleTreatmentCompany}}
        Year:  {{form.PoleTreatmentDateYear}}<br>
       <b>Pole ROW:</b> {{form.PoleRightOfWayStatus}}<br>
        
 
<!-- Create Station Assembly 1 Section Begin-->
       <b>Create Station Assembly 1: &nbsp&nbsp&nbsp<small>Idle{{form.StationAssemblyIdleIndicator1}}</small></b><br>
        &nbsp&nbsp&nbsp&nbsp Qt {{form.StationAssemblyNumberOfCopies1}}Cir# {{form.StationAssemblyCircuitNumber1}}
        A{{form.StationAssemblyPhaseAIndicator1}}
	B{{form.StationAssemblyPhaseBIndicator1}}
	C{{form.StationAssemblyPhaseCIndicator1}}
	N{{form.StationAssemblyPhaseNeutralIndicator1}} <br>
        &nbsp&nbsp&nbsp&nbsp Pri{{form.StationAssemblyPrimaryIndicator1}}
        Sec{{form.StationAssemblySecondaryIndicator1}}
        Ser{{form.StationAssemblyServiceIndicator1}}
        Open{{form.StationAssemblyOpenIndicator1}}<br>	       
	&nbsp&nbsp&nbsp&nbsp Unit:  {{form.StationAssemblyCompatibleUnit1}}<br>
        &nbsp&nbsp&nbsp&nbsp Tag#:  {{form.StationAssemblyTagNumber1}}
        Serial#:  {{form.StationAssemblySerialNumber1}} <br>
        
        
        &nbsp&nbsp&nbsp&nbsp Light{{form.StationAssemblyPoleLightIndicator1}}
        Meter{{form.StationAssemblyPoleMeterIndicator1}}
        Stub{{form.StationAssemblyPoleStubIndicator1}} <br>

        &nbsp&nbsp&nbsp&nbsp Year:  {{form.StationAssemblyPutIntoServiceDateYear1}}  
        Manu:  {{form.StationAssemblyManufacturer1}} <br>
        &nbsp&nbsp&nbsp&nbsp Owner:  {{form.StationAssemblyOwner1}}<br>
        &nbsp&nbsp&nbsp&nbsp Service Type:  {{form.StationAssemblyMeterServiceType1}}<br>
        &nbsp&nbsp&nbsp&nbsp Meter#:  {{form.StationAssemblyMeterNumber1}}
        DCSI#:  {{form.StationAssemblyMeterDCSINumber1}} <br>
        &nbsp&nbsp&nbsp&nbsp MeterForm:  {{form.StationAssemblyMeterForm1}} 
        MOP:  {{form.StationAssemblyMeterOnPoleIndicator1}}<br>
        &nbsp&nbsp&nbsp&nbsp Map#:  {{form.StationAssemblyMapNumber1}}<br>
        &nbsp&nbsp&nbsp&nbsp OldMap#:  {{form.StationAssemblyOldMapNumber1}}<br>
        &nbsp&nbsp&nbsp&nbsp Address:  {{form.StationAssemblyPhysicalAddress1}}<br>
<!-- Create Station Assembly 1 Section End--> 

<!-- Create Station Assembly 2 Section Begin-->
       <b>Create Station Assembly 2: &nbsp&nbsp&nbsp<small>Idle{{form.StationAssemblyIdleIndicator2}}</small></b><br>
        &nbsp&nbsp&nbsp&nbsp Qt {{form.StationAssemblyNumberOfCopies2}}Cir# {{form.StationAssemblyCircuitNumber2}}
        A{{form.StationAssemblyPhaseAIndicator2}}
	B{{form.StationAssemblyPhaseBIndicator2}}
	C{{form.StationAssemblyPhaseCIndicator2}}
	N{{form.StationAssemblyPhaseNeutralIndicator2}} <br>	       
	&nbsp&nbsp&nbsp&nbsp Pri{{form.StationAssemblyPrimaryIndicator2}}
        Sec{{form.StationAssemblySecondaryIndicator2}}
        Ser{{form.StationAssemblyServiceIndicator2}}
        Open{{form.StationAssemblyOpenIndicator2}}
        &nbsp&nbsp&nbsp&nbsp Unit:  {{form.StationAssemblyCompatibleUnit2}}<br>
<!-- Create Station Assembly 2 Section End--> 

<!-- Create Station Assembly 3 Section Begin-->
       <b>Create Station Assembly 3: &nbsp&nbsp&nbsp<small>Idle{{form.StationAssemblyIdleIndicator3}}</small></b><br>
        &nbsp&nbsp&nbsp&nbsp Qt {{form.StationAssemblyNumberOfCopies3}}Cir# {{form.StationAssemblyCircuitNumber3}}
        A{{form.StationAssemblyPhaseAIndicator3}}
	B{{form.StationAssemblyPhaseBIndicator3}}
	C{{form.StationAssemblyPhaseCIndicator3}}
	N{{form.StationAssemblyPhaseNeutralIndicator3}} <br>	       
	&nbsp&nbsp&nbsp&nbsp Pri{{form.StationAssemblyPrimaryIndicator3}}
        Sec{{form.StationAssemblySecondaryIndicator3}}
        Ser{{form.StationAssemblyServiceIndicator3}}
        Open{{form.StationAssemblyOpenIndicator3}}
        &nbsp&nbsp&nbsp&nbsp Unit:  {{form.StationAssemblyCompatibleUnit3}}<br>
<!-- Create Station Assembly 3 Section End--> 


<!-- Create Station Assembly 4 Section Begin-->
       <b>Create Station Assembly 4: &nbsp&nbsp&nbsp<small>Idle{{form.StationAssemblyIdleIndicator4}}</small></b><br>
        &nbsp&nbsp&nbsp&nbsp Qt {{form.StationAssemblyNumberOfCopies4}}Cir# {{form.StationAssemblyCircuitNumber4}}
        A{{form.StationAssemblyPhaseAIndicator4}}
	B{{form.StationAssemblyPhaseBIndicator4}}
	C{{form.StationAssemblyPhaseCIndicator4}}
	N{{form.StationAssemblyPhaseNeutralIndicator4}} <br>	       
	&nbsp&nbsp&nbsp&nbsp Pri{{form.StationAssemblyPrimaryIndicator4}}
        Sec{{form.StationAssemblySecondaryIndicator4}}
        Ser{{form.StationAssemblyServiceIndicator4}}
        Open{{form.StationAssemblyOpenIndicator4}}
        &nbsp&nbsp&nbsp&nbsp Unit:  {{form.StationAssemblyCompatibleUnit4}}<br>
<!-- Create Station Assembly 4 Section End--> 



<!-- Create Station Assembly 5 Section Begin-->
       <b>Create Station Assembly 5: &nbsp&nbsp&nbsp<small>Idle{{form.StationAssemblyIdleIndicator5}}</small></b><br>
        &nbsp&nbsp&nbsp&nbsp Qt {{form.StationAssemblyNumberOfCopies5}}Cir# {{form.StationAssemblyCircuitNumber5}}
        A{{form.StationAssemblyPhaseAIndicator5}}
	B{{form.StationAssemblyPhaseBIndicator5}}
	C{{form.StationAssemblyPhaseCIndicator5}}
	N{{form.StationAssemblyPhaseNeutralIndicator5}} <br>	       
	&nbsp&nbsp&nbsp&nbsp Pri{{form.StationAssemblyPrimaryIndicator5}}
        Sec{{form.StationAssemblySecondaryIndicator5}}
        Ser{{form.StationAssemblyServiceIndicator5}} 
        Open{{form.StationAssemblyOpenIndicator5}}
        &nbsp&nbsp&nbsp&nbsp Unit:  {{form.StationAssemblyCompatibleUnit5}}<br>
<!-- Create Station Assembly 5 Section End--> 

        <b>Pole Joint Use 1:</b>  {{form.PoleJointUseType1}}<br>
        &nbsp&nbsp&nbsp&nbsp Company:{{form.PoleJointUseCompany1}}<br>
        <b>Pole Joint Use 2:</b>  {{form.PoleJointUseType2}}<br>
        &nbsp&nbsp&nbsp&nbsp Company:{{form.PoleJointUseCompany2}}<br>
        <b>Pole Joint Use 3:</b>  {{form.PoleJointUseType3}}<br>
        &nbsp&nbsp&nbsp&nbsp Company:{{form.PoleJointUseCompany3}}<br>
        <b>Pole Joint Use 4:</b>  {{form.PoleJointUseType4}}<br>
        &nbsp&nbsp&nbsp&nbsp Company:{{form.PoleJointUseCompany4}}<br>
        <b>Pole Joint Use 5:</b>  {{form.PoleJointUseType5}}<br>
        &nbsp&nbsp&nbsp&nbsp Company:{{form.PoleJointUseCompany5}}<br>
        <b>Pole Joint Use 6:</b>  {{form.PoleJointUseType0}}<br>
        &nbsp&nbsp&nbsp&nbsp Company:{{form.PoleJointUseCompany0}}<br>





        
</small>
        </td><td valign=top width="300">
<small>
		<b>Span:</b>  {{form.SelectSpanid}} &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
		&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<input type="submit"/><br>
	New:  {{form.CreateSpanIndicator}}  Far Station ('Tag'):  {{form.SpanFarStation}} <br>
        Joint Trench:  {{form.SpanJointTrenchIndicator}} Delete:  {{form.DeleteSpanIndicator}}<br>
       
        Note{{form.SpanComment}} Tap{{form.SpanTapIndicator}} Update{{form.UpdateSpanCommentIndicator}}<br>
<!-- Create Span Assembly 1 Section Begin-->
	<b>Create Span Assembly 1:&nbsp&nbsp&nbsp<small>Idle{{form.SpanAssemblyIdleIndicator1}}</small></b><br>	   
	&nbsp&nbsp&nbsp&nbsp Cir# {{form.SpanAssemblyCircuitNumber1}}
        A{{form.SpanAssemblyPhaseAIndicator1}}
	B{{form.SpanAssemblyPhaseBIndicator1}}
	C{{form.SpanAssemblyPhaseCIndicator1}}
	N{{form.SpanAssemblyPhaseNeutralIndicator1}} <br>
        &nbsp&nbsp&nbsp&nbsp Primary{{form.SpanAssemblyPrimaryIndicator1}}
        Sec{{form.SpanAssemblySecondaryIndicator1}}
        Ser{{form.SpanAssemblyServiceIndicator1}}<br>
        
        &nbsp&nbsp&nbsp&nbsp Unit:  {{form.SpanAssemblyCompatibleUnit1}} <br>
<!-- Create Span Assembly 1 Section End-->

<!-- Create Span Assembly 2 Section Begin-->
        <b>Create Span Assembly 2:&nbsp&nbsp&nbsp<small>Idle{{form.SpanAssemblyIdleIndicator2}}</small></b><br>	   
	&nbsp&nbsp&nbsp&nbsp Cir# {{form.SpanAssemblyCircuitNumber2}}
        A{{form.SpanAssemblyPhaseAIndicator2}}
	B{{form.SpanAssemblyPhaseBIndicator2}}
	C{{form.SpanAssemblyPhaseCIndicator2}}
	N{{form.SpanAssemblyPhaseNeutralIndicator2}} <br>
        &nbsp&nbsp&nbsp&nbsp Primary{{form.SpanAssemblyPrimaryIndicator2}}
        Sec{{form.SpanAssemblySecondaryIndicator2}}
        Ser{{form.SpanAssemblyServiceIndicator2}}<br>
        
        &nbsp&nbsp&nbsp&nbsp Unit:  {{form.SpanAssemblyCompatibleUnit2}} <br>
<!-- Create Span Assembly 2 Section End-->

<!-- Create Span Assembly 3 Section Begin-->
        <b>Create Span Assembly 3:&nbsp&nbsp&nbsp<small>Idle{{form.SpanAssemblyIdleIndicator0}}</small></b><br>	   
	&nbsp&nbsp&nbsp&nbsp Cir# {{form.SpanAssemblyCircuitNumber0}}
        A{{form.SpanAssemblyPhaseAIndicator0}}
	B{{form.SpanAssemblyPhaseBIndicator0}}
	C{{form.SpanAssemblyPhaseCIndicator0}}
	N{{form.SpanAssemblyPhaseNeutralIndicator0}} <br>
        &nbsp&nbsp&nbsp&nbsp Primary{{form.SpanAssemblyPrimaryIndicator0}}
        Sec{{form.SpanAssemblySecondaryIndicator0}}
        Ser{{form.SpanAssemblyServiceIndicator0}}
        <br>
        &nbsp&nbsp&nbsp&nbsp Unit:  {{form.SpanAssemblyCompatibleUnit0}} <br>
<!-- Create Span Assembly 3 Section End-->
<br>



<small>
    {{Repeating Block Shortcut}}
</small>



<!-- Create Station Assembly 6 Section Begin-->
       <b>Create Station Assembly 6: &nbsp&nbsp&nbsp<small>Idle{{form.StationAssemblyIdleIndicator6}}</small></b><br>
        &nbsp&nbsp&nbsp&nbsp Qt {{form.StationAssemblyNumberOfCopies6}}Cir# {{form.StationAssemblyCircuitNumber6}}
        A{{form.StationAssemblyPhaseAIndicator6}}
	B{{form.StationAssemblyPhaseBIndicator6}}
	C{{form.StationAssemblyPhaseCIndicator6}}
	N{{form.StationAssemblyPhaseNeutralIndicator6}} <br>	       
	&nbsp&nbsp&nbsp&nbsp Pri{{form.StationAssemblyPrimaryIndicator6}}
        Sec{{form.StationAssemblySecondaryIndicator6}}
        Ser{{form.StationAssemblyServiceIndicator6}}
        Open{{form.StationAssemblyOpenIndicator6}}
        &nbsp&nbsp&nbsp&nbsp Unit:  {{form.StationAssemblyCompatibleUnit6}}<br>
<!-- Create Station Assembly 6 Section End--> 

<!-- Create Station Assembly 7 Section Begin-->
       <b>Create Station Assembly 7: &nbsp&nbsp&nbsp<small>Idle{{form.StationAssemblyIdleIndicator7}}</small></b><br>
        &nbsp&nbsp&nbsp&nbsp Qt {{form.StationAssemblyNumberOfCopies7}}Cir# {{form.StationAssemblyCircuitNumber7}}
        A{{form.StationAssemblyPhaseAIndicator7}}
	B{{form.StationAssemblyPhaseBIndicator7}}
	C{{form.StationAssemblyPhaseCIndicator7}}
	N{{form.StationAssemblyPhaseNeutralIndicator7}} <br>	       
	&nbsp&nbsp&nbsp&nbsp Pri{{form.StationAssemblyPrimaryIndicator7}}
        Sec{{form.StationAssemblySecondaryIndicator7}}
        Ser{{form.StationAssemblyServiceIndicator7}}
        Open{{form.StationAssemblyOpenIndicator7}}
        &nbsp&nbsp&nbsp&nbsp Unit:  {{form.StationAssemblyCompatibleUnit7}}<br>
<!-- Create Station Assembly 7 Section End--> 
<!-- Create Station Assembly 8 Section Begin-->
       <b>Create Station Assembly 8: &nbsp&nbsp&nbsp<small>Idle{{form.StationAssemblyIdleIndicator8}}</small></b><br>
        &nbsp&nbsp&nbsp&nbsp Qt {{form.StationAssemblyNumberOfCopies8}}Cir# {{form.StationAssemblyCircuitNumber8}}
        A{{form.StationAssemblyPhaseAIndicator8}}
	B{{form.StationAssemblyPhaseBIndicator8}}
	C{{form.StationAssemblyPhaseCIndicator8}}
	N{{form.StationAssemblyPhaseNeutralIndicator8}} <br>	       
	&nbsp&nbsp&nbsp&nbsp Pri{{form.StationAssemblyPrimaryIndicator8}}
        Sec{{form.StationAssemblySecondaryIndicator8}}
        Ser{{form.StationAssemblyServiceIndicator8}}
        Open{{form.StationAssemblyOpenIndicator8}}
        &nbsp&nbsp&nbsp&nbsp Unit:  {{form.StationAssemblyCompatibleUnit8}}<br>
<!-- Create Station Assembly 8 Section End--> 
<!-- Create Station Assembly 9 Section Begin-->
       <b>Create Station Assembly 9: &nbsp&nbsp&nbsp<small>Idle{{form.StationAssemblyIdleIndicator9}}</small></b><br>
        &nbsp&nbsp&nbsp&nbsp Qt {{form.StationAssemblyNumberOfCopies9}}Cir# {{form.StationAssemblyCircuitNumber9}}
        A{{form.StationAssemblyPhaseAIndicator9}}
	B{{form.StationAssemblyPhaseBIndicator9}}
	C{{form.StationAssemblyPhaseCIndicator9}}
	N{{form.StationAssemblyPhaseNeutralIndicator9}} <br>	       
	&nbsp&nbsp&nbsp&nbsp Pri{{form.StationAssemblyPrimaryIndicator9}}
        Sec{{form.StationAssemblySecondaryIndicator9}}
        Ser{{form.StationAssemblyServiceIndicator9}}
        Open{{form.StationAssemblyOpenIndicator9}}
        &nbsp&nbsp&nbsp&nbsp Unit:  {{form.StationAssemblyCompatibleUnit9}}<br>
<!-- Create Station Assembly 9 Section End--> 
<!-- Create Station Assembly 0 Section Begin-->
       <b>Create Station Assembly 10:&nbsp&nbsp&nbsp<small>Idle{{form.StationAssemblyIdleIndicator0}}</small></b><br>
        &nbsp&nbsp&nbsp&nbsp Qt {{form.StationAssemblyNumberOfCopies0}}Cir# {{form.StationAssemblyCircuitNumber0}}
        A{{form.StationAssemblyPhaseAIndicator0}}
	B{{form.StationAssemblyPhaseBIndicator0}}
	C{{form.StationAssemblyPhaseCIndicator0}}
	N{{form.StationAssemblyPhaseNeutralIndicator0}} <br>	       
	&nbsp&nbsp&nbsp&nbsp Pri{{form.StationAssemblyPrimaryIndicator0}}
        Sec{{form.StationAssemblySecondaryIndicator0}}
        Ser{{form.StationAssemblyServiceIndicator0}}
        Open{{form.StationAssemblyOpenIndicator0}}
        &nbsp&nbsp&nbsp&nbsp Unit:  {{form.StationAssemblyCompatibleUnit0}}<br>
<!-- Create Station Assembly 0 Section End-->        
        <b>Delete Assembly: </b> <small>[*STATION* or *SPAN* for all]</small>
	&nbsp&nbsp&nbsp&nbsp {{form.DeleteAssembly}} &nbsp&nbsp Keep:{{form.DeleteKeep}}<br>
        Map Selection &nbsp&nbsp&nbsp&nbsp {{form.Map}} 
	</small>
        </td>
      </table>

</form>
<td valign=top >
<div id="map">
{{OpenLayersJavaScript}}

</div>
        <a href="/coopgis/inventorycollection/admin/">Add New Compatible Unit</a><br>
        <a href="/coopgis/inventorycollection/exportcsv/">Create/View Export CSV File</a>
</td></tr>

<tr>
<td valign=top><h4>Nearby Span Information</h4><small>
	{% for line in SpanAssemblyList %}
	{{line}}<br>
	{% endfor %}
</small>
</td>
<td valign=top><h4>Nearby Station Information</h4><small>
	{% for line in StationAssemblyList %}
	 {{line}}<br>
	{% endfor %}
</small><td><br></tr>
</table>

  </body>
</html>"""





















def UpdateConditionEditorTemplate(NumberOfConditions, UserName=''):
    FileName='/opt/coopgis/djangoproject/templates/conditioneditor' + UserName + '.html'
    ReplacementBlockList=[]
    for i in range(0, NumberOfConditions):
        ReplacementBlockList.append(ConditionEditorTemplateRepeatingBlock.replace('{{repeatnumber}}', str(i)))
    ReplacementBlockString=''.join(ReplacementBlockList)
    FinalTemplate=ConditionEditorTemplate.replace('{{Repeating Block}}', ReplacementBlockString)
    FinalTemplate = FinalTemplate.replace('{{OpenLayersJavaScriptHeading}}', COOPGIS_Ajax.GetOpenLayersJavaScriptHeading())
    FinalTemplate = FinalTemplate.replace('{{OpenLayersJavaScript}}', COOPGIS_Ajax.GetOpenLayersJavaScript(FinalTemplate))
    try:
        os.remove(FileName)
    except OSError:
        pass
    TemplateFile=open(FileName, 'w')
    TemplateFile.write(FinalTemplate)
    TemplateFile.close()


#Condition Editor Section
ConditionEditorTemplate="""<!--
#    Copyright 2009, Tri-County Electric Cooperative, St. Matthews, South Carolina
#    This file is part of COOPGIS.
#    COOPGIS is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#    COOPGIS is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#    You should have received a copy of the GNU General Public License
#    along with COOPGIS.  If not, see <http://www.gnu.org/licenses/>.
**************************************************************************
THIS FILE WAS DYNAMICALLY GENERATED BY THE DYNAMIC TEMPLATE INCLUDE
MODIFICATIONS TO THIS FILE WILL BE PERIODICALLY OVERWRITTEN!!!!!
MODIFY THIS TEMPLATE IN THE DYNAMICTEMPLATE.PY FILE
**************************************************************************
-->

<html xmlns="http://www.w3.org/1999/xhtml">
  <head> 
    <style type="text/css">
        #map {
            width: 750px;
            height: 600px;
            border: 1px solid black;
        }
    </style>

{{OpenLayersJavaScriptHeading}}

    <title>COOPGIS Condition Editor</title>
  </head>
  <body onload="init()">
<b>{{LoginStatus}}</b>   &nbsp&nbsp&nbsp&nbsp <small><a href="/coopgis/">Main Menu</a></small><br>
<br>

<table width="100%">
<form method="post" action="">
<COLGROUP span="400" width="600">

<tr><td valign="top"><div id="map">
{{OpenLayersJavaScript}}
</div><br>

<table width="75%">
<tr>
</tr>
</table>
</td>
<td valign="top" width="50%">
         <small>Map {{form.Map}} &nbsp&nbsp&nbsp&nbsp<input type="submit"/><br>
         Select Using GPS{{form.SelectGPSIndicator}} {{GPSStatus}}<br>
         <b>Selection</b> Station {{form.SelectStationid}}
         Tag {{form.SelectTagNumber}}<br>
         RoadName {{form.SelectRoadName}}<br>
         MeterNumber {{form.SelectMeterNumber}}<br>
         DCSINumber {{form.SelectDCSINumber}}<br>

</colgroup>
<table> 
        {{Repeating Block}}
</table>
</td></tr>
</table>
</form>
<br>
</ul>
  </body>
</html>"""



ConditionEditorTemplateRepeatingBlock="""
        <tr><td valign="top">&nbsp</td><td valign="top">&nbsp</td></tr>
        <tr><td valign="top"><small>
			<b>Update: </b> {{form.UpdateIndicator{{repeatnumber}}}}
                        ID {{form.Conditionid{{repeatnumber}}}}<br>
                        Department {{form.ConditionDepartment{{repeatnumber}}}}<br>
                        Immediate{{form.PriorityImmediateIndicator{{repeatnumber}}}} 
                        ASAP{{form.PriorityASAPIndicator{{repeatnumber}}}} 
                        Routine{{form.PriorityRoutineIndicator{{repeatnumber}}}}<br>
                        Everything Fixed{{form.PriorityEverythingFixedMaintenanceOnlyIndicator{{repeatnumber}}}}
                        Everything Ok{{form.PriorityEverythingOkInspectionOnlyIndicator{{repeatnumber}}}}<br>
                        Vegetation Needs Attention{{form.PriorityVegetationNeedsAttentionIndicator{{repeatnumber}}}}<br>
                        <br>
                        <b>Reported</b> By{{form.PersonReporting{{repeatnumber}}}}
                        Date{{form.DateTimeReported{{repeatnumber}}}}<br>
                        Received By <b>Operations</b>{{form.ReceivedByOperationsIndicator{{repeatnumber}}}}
                        Date {{form.DateTimeReceivedByOperations{{repeatnumber}}}}<br>
                     
                        Station ID{{form.StationIdentifier{{repeatnumber}}}}
                        TagNumber{{form.TagNumber{{repeatnumber}}}}<br>
                       
                     
                        Description{{form.Description{{repeatnumber}}}}<br>
                        <br>
                        <b>Work</b> Order Number{{form.WorkOrderNumber{{repeatnumber}}}} <br>
                        Remarks{{form.WorkRemarks{{repeatnumber}}}}<br>
                        Performed By{{form.WorkPerformedBy{{repeatnumber}}}}
                        Hours{{form.WorkHours{{repeatnumber}}}}<br>
                        Date{{form.WorkDate{{repeatnumber}}}}
                        Completed{{form.WorkCompletedIndicator{{repeatnumber}}}}
                        Not Completed{{form.WorkNotCompletedIndicator{{repeatnumber}}}}<br>
                        Not Completed Reason{{form.WorkNotCompletedDescription{{repeatnumber}}}}<br>
                        <br>
                        <b>Foreman</b>{{form.WorkForeman{{repeatnumber}}}}
                        Signoff{{form.WorkForemanSignoffIndicator{{repeatnumber}}}}
                        Date{{form.WorkForemanSignoffDateTime{{repeatnumber}}}}<br>
                        <br>
                        <b>Review</b> {{form.ReviewIndicator{{repeatnumber}}}}
                        Additional Attention Needed{{form.ReviewAdditionalAttentionNeededIndicator{{repeatnumber}}}}<br>  
                        Comments{{form.ReviewComments{{repeatnumber}}}}<br>
                        UserName{{form.ReviewUserName{{repeatnumber}}}}<br>
                        DateTime{{form.ReviewDateTime{{repeatnumber}}}}<br>
                        <br>
                        Deleted {{form.DeletedIndicator{{repeatnumber}}}}<br>
                        <br>
                        <b>Archived</b>{{form.ArchivedIndicator{{repeatnumber}}}}
                        UserName{{form.ArchivedUserName{{repeatnumber}}}}
                        Date{{form.ArchivedDateTime{{repeatnumber}}}}<br>
                        <b>Create</b> Date {{form.CreateDateTime{{repeatnumber}}}}
                        UserName{{form.CreateUserName{{repeatnumber}}}}<br>
                        <b>Last Modify</b> Date {{form.LastModifyDateTime{{repeatnumber}}}}
                        UserName{{form.LastModifyUserName{{repeatnumber}}}}<br>
                        </small></td></tr> """


#Condition Create Section
def UpdateConditionCreateTemplate(NumberOfConditions, UserName=''):
    FileName='/opt/coopgis/djangoproject/templates/conditioncreate' + UserName + '.html'
    ReplacementBlockList=[]
    for i in range(0, NumberOfConditions):
        ReplacementBlockList.append(ConditionCreateTemplateRepeatingBlock.replace('{{repeatnumber}}', str(i)))
    ReplacementBlockString=''.join(ReplacementBlockList)
    FinalTemplate=ConditionCreateTemplate.replace('{{Repeating Block}}', ReplacementBlockString)
    FinalTemplate = FinalTemplate.replace('{{OpenLayersJavaScriptHeading}}', COOPGIS_Ajax.GetOpenLayersJavaScriptHeading())
    FinalTemplate = FinalTemplate.replace('{{OpenLayersJavaScript}}', COOPGIS_Ajax.GetOpenLayersJavaScript(OpenLayersJavaScriptHeading=FinalTemplate))
    try:
        os.remove(FileName)
    except OSError:
        pass
    TemplateFile=open(FileName, 'w')
    TemplateFile.write(FinalTemplate)
    TemplateFile.close()


ConditionCreateTemplate="""<!--
#    Copyright 2009, Tri-County Electric Cooperative, St. Matthews, South Carolina
#    This file is part of COOPGIS.
#    COOPGIS is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#    COOPGIS is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#    You should have received a copy of the GNU General Public License
#    along with COOPGIS.  If not, see <http://www.gnu.org/licenses/>.
**************************************************************************
THIS FILE WAS DYNAMICALLY GENERATED BY THE DYNAMIC TEMPLATE INCLUDE
MODIFICATIONS TO THIS FILE WILL BE PERIODICALLY OVERWRITTEN!!!!!
MODIFY THIS TEMPLATE IN THE DYNAMICTEMPLATE.PY FILE
**************************************************************************
-->

<html xmlns="http://www.w3.org/1999/xhtml">
  <head> 
    <style type="text/css">
        #map{
            width: 400px;
            height: 600px;
            border: 1px solid black;
            }
    </style>
    {{OpenLayersJavaScriptHeading}}
    <title>COOPGIS Condition Create</title>
  </head>

  <body onload="init()">
  <b>{{LoginStatus}}</b>   &nbsp&nbsp&nbsp&nbsp <small><a href="/coopgis/">Main Menu</a></small><br>
  <br>

  <table style = "width:100%" border = "1">
  <form method="post" action="">
  <col width = "400">
    <tr>
        <td rowspan = "4">
          <div id="map">
            {{OpenLayersJavaScript}}
          </div>
        </td>
        <td valign = "top">
    	    <small>Map {{form.Map}} 
    	    Select Using GPS{{form.SelectGPSIndicator}} {{GPSStatus}}
            <input type="submit"/>
        </td>
    <tr>
        <td>
    	    <b>Selection</b><br>
            Station {{form.SelectStationid}}
            Tag {{form.SelectStationTagNumber}}
            RoadName {{form.SelectRoadName}}<br>
            MeterNumber {{form.SelectMeterNumber}}
            DCSINumber {{form.SelectDCSINumber}}
        </td>
    </tr>
    <tr>
        <td valign = "top">
            <table>
                {{Repeating Block}}
            </table>
        </td>
    </tr>
    <tr><td></td></tr>
  </table>
</form>
<br>
</ul>
  </body>
</html>"""



ConditionCreateTemplateRepeatingBlock="""
	<tr>
            <td colspan = "8">
                <b>Update:</b>  {{form.UpdateIndicator{{repeatnumber}}}}
                ID {{form.Conditionid{{repeatnumber}}}}
                Department {{form.ConditionDepartment{{repeatnumber}}}}
                Immediate{{form.PriorityImmediateIndicator{{repeatnumber}}}} 
                ASAP{{form.PriorityASAPIndicator{{repeatnumber}}}} 
                Routine{{form.PriorityRoutineIndicator{{repeatnumber}}}}
            </td>
        </tr>
        <tr>
            <td colspan = "8">
                Everything Fixed{{form.PriorityEverythingFixedMaintenanceOnlyIndicator{{repeatnumber}}}}
                Everything Ok{{form.PriorityEverythingOkInspectionOnlyIndicator{{repeatnumber}}}}
                Vegetation Needs Attention{{form.PriorityVegetationNeedsAttentionIndicator{{repeatnumber}}}}
                <br><br>
            </td>
        </tr>        
        <tr>
            <td>Pole </td><td>{{form.PoleConditionStatus{{repeatnumber}}}}</td>
            <td>GuyAnchor </td><td>{{form.GuyAnchorConditionStatus{{repeatnumber}}}}</td>
            <td>Insulator </td><td>{{form.InsulatorConditionStatus{{repeatnumber}}}}</td>
            <td>Conductor </td><td>{{form.ConductorConditionStatus{{repeatnumber}}}}</td>
        </tr>
        <tr>
            <td>RightOfWay </td><td>{{form.RightOfWayConditionStatus{{repeatnumber}}}}</td>
            <td>PadMount </td><td>{{form.PadMountConditionStatus{{repeatnumber}}}}</td>
            <td>Vault </td><td>{{form.VaultConditionStatus{{repeatnumber}}}}
            <td>RiserCable </td><td>{{form.RiserCableConditionStatus{{repeatnumber}}}}</td>
        </tr>
        <br>
        <tr>
            <td colspan = "8">
                <br><b>Reported</b> By{{form.PersonReporting{{repeatnumber}}}}
                Date{{form.DateTimeReported{{repeatnumber}}}}
                Received By <b>Operations</b>{{form.ReceivedByOperationsIndicator{{repeatnumber}}}}
                Date {{form.DateTimeReceivedByOperations{{repeatnumber}}}}
                <br> 
            </td>
        </tr>
        <tr>
            <td colspan = "8">
                Station ID{{form.StationIdentifier{{repeatnumber}}}}
                TagNumber{{form.TagNumber{{repeatnumber}}}}
                Description{{form.Description{{repeatnumber}}}}
             </td>
        </tr> """



#Condition Work Section
def UpdateConditionWorkTemplate(NumberOfConditions, UserName=''):
    FileName='/opt/coopgis/djangoproject/templates/conditionwork' + UserName + '.html'
    ReplacementBlockList=[]
    for i in range(0, NumberOfConditions):
        ReplacementBlockList.append(ConditionWorkTemplateRepeatingBlock.replace('{{repeatnumber}}', str(i)))
    ReplacementBlockString=''.join(ReplacementBlockList)
    FinalTemplate=ConditionWorkTemplate.replace('{{Repeating Block}}', ReplacementBlockString)
    FinalTemplate = FinalTemplate.replace('{{OpenLayersJavaScriptHeading}}', COOPGIS_Ajax.GetOpenLayersJavaScriptHeading())
    FinalTemplate = FinalTemplate.replace('{{OpenLayersJavaScript}}', COOPGIS_Ajax.GetOpenLayersJavaScript(OpenLayersJavaScriptHeading=FinalTemplate))
    try:
        os.remove(FileName)
    except OSError:
        pass
    TemplateFile=open(FileName, 'w')
    TemplateFile.write(FinalTemplate)
    TemplateFile.close()


ConditionWorkTemplate="""<!--
#    Copyright 2009, Tri-County Electric Cooperative, St. Matthews, South Carolina
#    This file is part of COOPGIS.
#    COOPGIS is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#    COOPGIS is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#    You should have received a copy of the GNU General Public License
#    along with COOPGIS.  If not, see <http://www.gnu.org/licenses/>.
**************************************************************************
THIS FILE WAS DYNAMICALLY GENERATED BY THE DYNAMIC TEMPLATE INCLUDE
MODIFICATIONS TO THIS FILE WILL BE PERIODICALLY OVERWRITTEN!!!!!
MODIFY THIS TEMPLATE IN THE DYNAMICTEMPLATE.PY FILE
**************************************************************************
-->

<html xmlns="http://www.w3.org/1999/xhtml">
  <head> 
    <style type="text/css">
        #map {
            width: 750px;
            height: 600px;
            border: 1px solid black;
        }
    </style>
{{OpenLayersJavaScriptHeading}}

    <title>COOPGIS Condition Work</title>
  </head>
  <body onload="init()">
<b>{{LoginStatus}}</b>   &nbsp&nbsp&nbsp&nbsp <small><a href="/coopgis/">Main Menu</a></small><br>
<br>

<table width="100%">
<form method="post" action="">
<COLGROUP span="400" width="600">

<tr><td valign="top"><div id="map">
{{OpenLayersJavaScript}}
</div><br>

<table width="75%">
<tr>
</tr>
</table>
</td>
<td valign="top" width="50%">
         <small>Map {{form.Map}} &nbsp&nbsp&nbsp&nbsp<input type="submit"/><br>
         Select Using GPS{{form.SelectGPSIndicator}} {{GPSStatus}}<br>
         <b>Selection</b> Station {{form.SelectStationid}}
         Tag {{form.SelectTagNumber}}<br>
         RoadName {{form.SelectRoadName}}<br>
         MeterNumber {{form.SelectMeterNumber}}<br>
         DCSINumber {{form.SelectDCSINumber}}<br>

</colgroup>
<table> 
        {{Repeating Block}}
</table>
</td></tr>
</table>
</form>
<br>
</ul>
  </body>
</html>"""



ConditionWorkTemplateRepeatingBlock="""
        <tr><td valign="top">&nbsp</td><td valign="top">&nbsp</td></tr>
        <tr><td valign="top"><small>
			<b>Update:</b>  {{form.UpdateIndicator{{repeatnumber}}}}
                        ID {{form.Conditionid{{repeatnumber}}}}<br>
                        Station ID{{form.StationIdentifier{{repeatnumber}}}}
                        TagNumber{{form.TagNumber{{repeatnumber}}}}<br>

                        <b>Work</b> Order Number{{form.WorkOrderNumber{{repeatnumber}}}} <br>
                        Remarks{{form.WorkRemarks{{repeatnumber}}}}<br>
                        Performed By{{form.WorkPerformedBy{{repeatnumber}}}}
                        Hours{{form.WorkHours{{repeatnumber}}}}<br>
                        Date{{form.WorkDate{{repeatnumber}}}}
                        Completed{{form.WorkCompletedIndicator{{repeatnumber}}}}
                        Not Completed{{form.WorkNotCompletedIndicator{{repeatnumber}}}}<br>
                        Not Completed Reason{{form.WorkNotCompletedDescription{{repeatnumber}}}}<br>
                        <br>
                        <b>Foreman</b>{{form.WorkForeman{{repeatnumber}}}}
                        Signoff{{form.WorkForemanSignoffIndicator{{repeatnumber}}}}
                        Date{{form.WorkForemanSignoffDateTime{{repeatnumber}}}}<br>
                        <br></td></tr> """

#Condition Review Section
def UpdateConditionReviewTemplate(NumberOfConditions, UserName=''):
    FileName='/opt/coopgis/djangoproject/templates/conditionreview' + UserName + '.html'
    ReplacementBlockList=[]
    for i in range(0, NumberOfConditions):
        ReplacementBlockList.append(ConditionReviewTemplateRepeatingBlock.replace('{{repeatnumber}}', str(i)))
    ReplacementBlockString=''.join(ReplacementBlockList)
    FinalTemplate=ConditionReviewTemplate.replace('{{Repeating Block}}', ReplacementBlockString)
    FinalTemplate = FinalTemplate.replace('{{OpenLayersJavaScriptHeading}}', COOPGIS_Ajax.GetOpenLayersJavaScriptHeading())
    FinalTemplate = FinalTemplate.replace('{{OpenLayersJavaScript}}', COOPGIS_Ajax.GetOpenLayersJavaScript(OpenLayersJavaScriptHeading=FinalTemplate))
    try:
        os.remove(FileName)
    except OSError:
        pass
    TemplateFile=open(FileName, 'w')
    TemplateFile.write(FinalTemplate)
    TemplateFile.close()



ConditionReviewTemplate="""<!--
#    Copyright 2009, Tri-County Electric Cooperative, St. Matthews, South Carolina
#    This file is part of COOPGIS.
#    COOPGIS is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#    COOPGIS is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#    You should have received a copy of the GNU General Public License
#    along with COOPGIS.  If not, see <http://www.gnu.org/licenses/>.
**************************************************************************
THIS FILE WAS DYNAMICALLY GENERATED BY THE DYNAMIC TEMPLATE INCLUDE
MODIFICATIONS TO THIS FILE WILL BE PERIODICALLY OVERWRITTEN!!!!!
MODIFY THIS TEMPLATE IN THE DYNAMICTEMPLATE.PY FILE
**************************************************************************
-->

<html xmlns="http://www.w3.org/1999/xhtml">
  <head> 
    <style type="text/css">
        #map {
            width: 750px;
            height: 600px;
            border: 1px solid black;
        }
    </style>
{{OpenLayersJavaScriptHeading}}

    <title>COOPGIS Condition Work</title>
  </head>
  <body onload="init()">
<b>{{LoginStatus}}</b>   &nbsp&nbsp&nbsp&nbsp <small><a href="/coopgis/">Main Menu</a></small><br>
<br>

<table width="100%">
<form method="post" action="">
<COLGROUP span="400" width="600">

<tr><td valign="top"><div id="map">
{{OpenLayersJavaScript}}
</div><br>

<table width="75%">
<tr>
</tr>
</table>
</td>
<td valign="top" width="50%">
         <small>Map {{form.Map}} &nbsp&nbsp&nbsp&nbsp<input type="submit"/><br>
         Select Using GPS{{form.SelectGPSIndicator}} {{GPSStatus}}<br>
         <b>Selection</b> Station {{form.SelectStationid}}
         Tag {{form.SelectTagNumber}}<br>
         RoadName {{form.SelectRoadName}}<br>
         MeterNumber {{form.SelectMeterNumber}}<br>
         DCSINumber {{form.SelectDCSINumber}}<br>

</colgroup>
<table> 
        {{Repeating Block}}
</table>
</td></tr>
</table>
</form>
<br>
</ul>
  </body>
</html>"""






ConditionReviewTemplateRepeatingBlock="""
        <tr><td valign="top">&nbsp</td><td valign="top">&nbsp</td></tr>
        <tr><td valign="top"><small>
			<b>Update:</b>  {{form.UpdateIndicator{{repeatnumber}}}}
                        ID {{form.Conditionid{{repeatnumber}}}}<br>                        
                     
                        Station ID{{form.StationIdentifier{{repeatnumber}}}}
                        TagNumber{{form.TagNumber{{repeatnumber}}}}<br>
                     
                        <b>Review</b> {{form.ReviewIndicator{{repeatnumber}}}}
                        Additional Attention Needed{{form.ReviewAdditionalAttentionNeededIndicator{{repeatnumber}}}}<br>  
                        Comments{{form.ReviewComments{{repeatnumber}}}}<br>
                        UserName{{form.ReviewUserName{{repeatnumber}}}}<br>
                        DateTime{{form.ReviewDateTime{{repeatnumber}}}}<br>
                        <br>
                        Deleted {{form.DeletedIndicator{{repeatnumber}}}}<br>
                        <br>
                        <b>Archived</b>{{form.ArchivedIndicator{{repeatnumber}}}}
                        UserName{{form.ArchivedUserName{{repeatnumber}}}}
                        Date{{form.ArchivedDateTime{{repeatnumber}}}}<br>
                        <b>Create</b> Date {{form.CreateDateTime{{repeatnumber}}}}
                        UserName{{form.CreateUserName{{repeatnumber}}}}<br>
                        <b>Last Modify</b> Date {{form.LastModifyDateTime{{repeatnumber}}}}
                        UserName{{form.LastModifyUserName{{repeatnumber}}}}<br>
                        </small></td></tr> """



#Condition Dispatch Section
def UpdateConditionDispatchTemplate(NumberOfConditions, UserName=''):
    FileName='/opt/coopgis/djangoproject/templates/conditiondispatch' + UserName + '.html'
    ReplacementBlockList=[]
    for i in range(0, NumberOfConditions):
        ReplacementBlockList.append(ConditionDispatchTemplateRepeatingBlock.replace('{{repeatnumber}}', str(i)))
    ReplacementBlockString=''.join(ReplacementBlockList)
    FinalTemplate=ConditionDispatchTemplate.replace('{{Repeating Block}}', ReplacementBlockString)
    FinalTemplate = FinalTemplate.replace('{{OpenLayersJavaScriptHeading}}', COOPGIS_Ajax.GetOpenLayersJavaScriptHeading())
    FinalTemplate = FinalTemplate.replace('{{OpenLayersJavaScript}}', COOPGIS_Ajax.GetOpenLayersJavaScript(OpenLayersJavaScriptHeading=FinalTemplate))
    try:
        os.remove(FileName)
    except OSError:
        pass
    TemplateFile=open(FileName, 'w')
    TemplateFile.write(FinalTemplate)
    TemplateFile.close()



ConditionDispatchTemplate="""<!--
#    Copyright 2009 Tri-County Electric Cooperative, St. Matthews, South Carolina
#    This file is part of COOPGIS.
#    COOPGIS is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#    COOPGIS is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#    You should have received a copy of the GNU General Public License
#    along with COOPGIS.  If not, see <http://www.gnu.org/licenses/>.
**************************************************************************
THIS FILE WAS DYNAMICALLY GENERATED BY THE DYNAMIC TEMPLATE INCLUDE
MODIFICATIONS TO THIS FILE WILL BE PERIODICALLY OVERWRITTEN!!!!!
MODIFY THIS TEMPLATE IN THE DYNAMICTEMPLATE.PY FILE
**************************************************************************
-->

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>COOPGIS Condition Dispatch</title>
  </head>
<body>

<b>{{LoginStatus}}</b>   &nbsp&nbsp&nbsp&nbsp <small><a href="/coopgis/">Main Menu</a></small><br>

<h4>Condition Dispatch</h4>
<form method="post" action="">
Display All:  {{form.ShowAllIndicator}} &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp <input type="submit"/><br>
Vegetation Only:  {{form.OnlyShowVegetationIndicator}}<br>
Archived Only:  {{form.OnlyShowArchivedIndicator}}<br>

<br>
<table>
{{Repeating Block}}
</table>
</form>
  </body>
</html>
"""






ConditionDispatchTemplateRepeatingBlock="""
	<tr>
	<td valign='top'><b>Update</b> {{form.UpdateIndicator{{repeatnumber}}}} <br>
            ID {{form.Conditionid{{repeatnumber}}}}<br>
            {{form.ConditionDepartment{{repeatnumber}}}}<br>
            {{form.PriorityString{{repeatnumber}}}}</td>
	<td valign='top'>Assigned: {{form.CurrentAssignment{{repeatnumber}}}}<br>
		Reported:{{form.DateTimeReported{{repeatnumber}}}}</td>
        <td valign='top'>Station:  {{form.StationIdentifier{{repeatnumber}}}}<br>
            Tag:  {{form.TagNumber{{repeatnumber}}}}<br></td>
	<td><br>
            </td>
	<td valign='top'>Description:<br>{{form.Description{{repeatnumber}}}}</td>
        <td valign='top'>Worker: {{form.WorkPerformedBy{{repeatnumber}}}}<br>
            Hours: {{form.WorkHours{{repeatnumber}}}}<br>
            Date: {{form.WorkDate{{repeatnumber}}}}</td>
	<td valign='top'>Work Remarks{{form.WorkRemarks{{repeatnumber}}}}</td>
        <td valign='top'>Done{{form.WorkCompletedIndicator{{repeatnumber}}}}<br>
            Not Done{{form.WorkNotCompletedIndicator{{repeatnumber}}}}<br>
            Explanation{{form.WorkNotCompletedDescription{{repeatnumber}}}}</td>
        <td valign='top'>Reviewed{{form.ReviewIndicator{{repeatnumber}}}}<br>
            Attention Needed{{form.ReviewAdditionalAttentionNeededIndicator{{repeatnumber}}}}<br>
	    Notes {{form.ReviewComments{{repeatnumber}}}}</td>
	<td valign='top'>Archive{{form.ArchivedIndicator{{repeatnumber}}}}</td>
	</tr>
 """






def BuildSubstationEquipmentInspectionTemplate(substationEquipmentTemplate):
    Header="""
<!--
#    Copyright 2010 Tri-County Electric Cooperative, St. Matthews, South Carolina
#    This file is part of COOPGIS.
#    COOPGIS is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#    COOPGIS is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#    You should have received a copy of the GNU General Public License
#    along with COOPGIS.  If not, see <http://www.gnu.org/licenses/>.
**************************************************************************
THIS FILE WAS DYNAMICALLY GENERATED BY THE DYNAMIC TEMPLATE INCLUDE
MODIFICATIONS TO THIS FILE WILL BE PERIODICALLY OVERWRITTEN!!!!!
MODIFY THIS TEMPLATE IN THE DYNAMICTEMPLATE.PY FILE
**************************************************************************
-->


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>COOPGIS Substation Equipment Inspection:  {{Substation}} {{SubstationEquipment}}</title>
</head>

<body>
 <b> <large>COOPGIS Substation Equipment Inspection:  {{Substation}} {{SubstationEquipment}}
</large></b> &nbsp&nbsp&nbsp&nbsp <small><a href="/coopgis/substation/">Substation Main Menu</a></small><br><br><br>

<form method="post" action="">

<table>
<tr><td></td><td><input type="submit" value="Submit"/></td></tr>
<tr><td>New {{form.NewIndicator}}</td><td>Update {{form.UpdateIndicator}}</td></tr>
<tr><td>Selection {{form.SubstationEquipmentInspectionSelection}}</td></tr>
<tr><td>&nbsp</td></tr>
<tr><td>&nbsp</td><td>id {{form.SubstationEquipmentInspectionid}}</td></tr>
<tr><td>Create Date {{form.CreateDateTime}}</td><td>Create User {{form.CreateUserName}}</tr>
<tr><td>Last Modify Date {{form.LastModifyDateTime}}</td><td>Last Modify User {{form.LastModifyUserName}}</td></tr>
"""
    Footer="""</table>
</form>
  </body>
</html>
"""
    if(not substationEquipmentTemplate):
       return Header + """ 
<tr><td>Description {{form.Description}}</td></tr>
<tr><td>Battery Voltage {{form.BatteryTest}}</td></tr>
<tr><td>Battery Charge {{form.BatteryCharge}}</td></tr>
<tr><td>Battery Visual {{form.BatteryVisual}}</td></tr>
<tr><td>Battery Voltage Test {{form.BatteryVoltageTest}}</td></tr>
<tr><td>Battery Voltage Normal {{form.BatteryVoltageNormal}}</td></tr>
<tr><td>Ground {{form.Ground}}</td></tr>
<tr><td>Visual {{form.Visual}}</td></tr>
<tr><td>MeterKWH {{form.MeterKWH}}</td></tr>
<tr><td>MeterKW {{form.MeterKW}}</td></tr>
<tr><td>RecloserAmperageA {{form.RecloserAmperageA}}</td></tr>
<tr><td>RecloserAmperageB {{form.RecloserAmperageB}}</td></tr>
<tr><td>RecloserAmperageC {{form.RecloserAmperageC}}</td></tr>
<tr><td>RecloserAmperageGround {{form.RecloserAmperageGround}}</td></tr>
<tr><td>RecloserMaxDemandA {{form.RecloserMaxDemandA}}</td></tr>
<tr><td>RecloserMaxDemandB {{form.RecloserMaxDemandB}}</td></tr>
<tr><td>RecloserMaxDemandC {{form.RecloserMaxDemandC}}</td></tr>
<tr><td>RecloserMaxDemandGround {{form.RecloserMaxDemandGround}}</td></tr>
<tr><td>RecloserOperationSummaryA {{form.RecloserOperationSummaryA}}</td></tr>
<tr><td>RecloserOperationSummaryB {{form.RecloserOperationSummaryB}}</td></tr>
<tr><td>RecloserOperationSummaryC {{form.RecloserOperationSummaryC}}</td></tr>
<tr><td>RecloserTargetA {{form.RecloserTargetA}}</td></tr>
<tr><td>RecloserTargetB {{form.RecloserTargetB}}</td></tr>
<tr><td>RecloserTargetC {{form.RecloserTargetC}}</td></tr>
<tr><td>RecloserTargetGround {{form.RecloserTargetGround}}</td></tr>
<tr><td>RegulatorDragHandPositionMinimum {{form.RegulatorDragHandPositionMinimum}}</td></tr>
<tr><td>RegulatorDragHandPositionCurrent {{form.RegulatorDragHandPositionCurrent}}</td></tr>
<tr><td>RegulatorDragHandPositionMaximum {{form.RegulatorDragHandPositionMaximum}}</td></tr>
<tr><td>RegulatorVoltHigh {{form.RegulatorVoltHigh}}</td></tr>
<tr><td>RegulatorVoltLow {{form.RegulatorVoltLow}}</td></tr>
<tr><td>RegulatorVoltCurrent {{form.RegulatorVoltCurrent}}</td></tr>
<tr><td>RegulatorMaxAmp {{form.RegulatorMaxAmp}}</td></tr>
<tr><td>SurgeProtectorVisual {{form.SurgeProtectorVisual}}</td></tr>
<tr><td>TransformerOilLeak {{form.TransformerOilLeak}}</td></tr>
<tr><td>TransformerNitrogenPressure {{form.TransformerNitrogenPressure}}</td></tr>
<tr><td>TransformerOilVisual {{form.TransformerOilVisual}}</td></tr>
<tr><td>TransformerOilTemperatureCurrent {{form.TransformerOilTemperatureCurrent}}</td></tr>
<tr><td>TransformerOilTemperatureMaximum {{form.TransformerOilTemperatureMaximum}}</td></tr>
<tr><td>TransformerWindingTemperatureCurrent {{form.TransformerWindingTemperatureCurrent}}</td></tr>
<tr><td>TransformerWindingTemperatureMaximum {{form.TransformerWindingTemperatureMaximum}}</td></tr>
<tr><td>MechanismCharge {{form.MechanismCharge}}</td></tr>
<tr><td>Operation Counter {{form.OperationCounter}}</td></tr>
<tr><td>Fan Working Visual {{form.FanWorkingVisual}}</td></tr>
<tr><td>Demand Amp A {{form.DemandAmpA}}</td></tr>
<tr><td>Demand Amp B {{form.DemandAmpB}}</td></tr>
<tr><td>Demand Amp C {{form.DemandAmpC}}</td></tr>
<tr><td>Over Current Trip {{form.OverCurrentTrip}}</td></tr>
<tr><td>Breaker Counter {{form.BreakerCounter}}</td></tr>
""" + Footer
    #If here, a Substation Equipment Template exists, so use it to build the form
    BodyDict={}
    if(substationEquipmentTemplate.DescriptionOrder):
        BodyDict['Description']=substationEquipmentTemplate.DescriptionOrder
    if(substationEquipmentTemplate.BatteryVoltageTestOrder):
        BodyDict['Battery Voltage Test']=substationEquipmentTemplate.BatteryVoltageTestOrder
    if(substationEquipmentTemplate.BatteryVoltageNormalOrder):
        BodyDict['Battery Voltage Normal']=substationEquipmentTemplate.BatteryVoltageNormalOrder
    if(substationEquipmentTemplate.BatteryChargeOrder):
        BodyDict['Battery Charge']=substationEquipmentTemplate.BatteryChargeOrder
    if(substationEquipmentTemplate.BatteryVisualOrder):
        BodyDict['Battery Visual']=substationEquipmentTemplate.BatteryVisualOrder
    if(substationEquipmentTemplate.GroundOrder):
        BodyDict['Ground']=substationEquipmentTemplate.GroundOrder
    if(substationEquipmentTemplate.VisualOrder):
        BodyDict['Visual']=substationEquipmentTemplate.VisualOrder
    if(substationEquipmentTemplate.MeterKWHOrder):
        BodyDict['Meter KWH']=substationEquipmentTemplate.MeterKWHOrder
    if(substationEquipmentTemplate.MeterKWOrder):
        BodyDict['Meter KW']=substationEquipmentTemplate.MeterKWOrder
    if(substationEquipmentTemplate.RecloserAmperageAOrder):
        BodyDict['Recloser Amperage A']=substationEquipmentTemplate.RecloserAmperageAOrder
    if(substationEquipmentTemplate.RecloserAmperageBOrder):
        BodyDict['Recloser Amperage B']=substationEquipmentTemplate.RecloserAmperageBOrder
    if(substationEquipmentTemplate.RecloserAmperageCOrder):
        BodyDict['Recloser Amperage C']=substationEquipmentTemplate.RecloserAmperageCOrder
    if(substationEquipmentTemplate.RecloserAmperageGroundOrder):
        BodyDict['Recloser Amperage Ground']=substationEquipmentTemplate.RecloserAmperageGroundOrder
    if(substationEquipmentTemplate.RecloserMaxDemandAOrder):
        BodyDict['Recloser Max Demand A']=substationEquipmentTemplate.RecloserMaxDemandAOrder
    if(substationEquipmentTemplate.RecloserMaxDemandBOrder):
        BodyDict['Recloser Max Demand B']=substationEquipmentTemplate.RecloserMaxDemandBOrder
    if(substationEquipmentTemplate.RecloserMaxDemandCOrder):
        BodyDict['Recloser Max Demand C']=substationEquipmentTemplate.RecloserMaxDemandCOrder
    if(substationEquipmentTemplate.RecloserMaxDemandGroundOrder):
        BodyDict['Recloser Max Demand Ground']=substationEquipmentTemplate.RecloserMaxDemandGroundOrder
    if(substationEquipmentTemplate.RecloserOperationSummaryAOrder):
        BodyDict['Recloser Operation Summary A']=substationEquipmentTemplate.RecloserOperationSummaryAOrder
    if(substationEquipmentTemplate.RecloserOperationSummaryBOrder):
        BodyDict['Recloser Operation Summary B']=substationEquipmentTemplate.RecloserOperationSummaryBOrder
    if(substationEquipmentTemplate.RecloserOperationSummaryCOrder):
        BodyDict['Recloser Operation Summary C']=substationEquipmentTemplate.RecloserOperationSummaryCOrder
    if(substationEquipmentTemplate.RecloserTargetAOrder):
        BodyDict['Recloser Target A']=substationEquipmentTemplate.RecloserTargetAOrder
    if(substationEquipmentTemplate.RecloserTargetBOrder):
        BodyDict['Recloser Target B']=substationEquipmentTemplate.RecloserTargetBOrder
    if(substationEquipmentTemplate.RecloserTargetCOrder):
        BodyDict['Recloser Target C']=substationEquipmentTemplate.RecloserTargetCOrder
    if(substationEquipmentTemplate.RecloserTargetGroundOrder):
        BodyDict['Recloser Target Ground']=substationEquipmentTemplate.RecloserTargetGroundOrder
    if(substationEquipmentTemplate.RegulatorDragHandPositionMinimumOrder):
        BodyDict['Regulator Drag Hand Position Minimum']=substationEquipmentTemplate.RegulatorDragHandPositionMinimumOrder
    if(substationEquipmentTemplate.RegulatorDragHandPositionCurrentOrder):
        BodyDict['Regulator Drag Hand Position Current']=substationEquipmentTemplate.RegulatorDragHandPositionCurrentOrder
    if(substationEquipmentTemplate.RegulatorDragHandPositionMaximumOrder):
        BodyDict['Regulator Drag Hand Position Maximum']=substationEquipmentTemplate.RegulatorDragHandPositionMaximumOrder
    if(substationEquipmentTemplate.RegulatorVoltHighOrder):
        BodyDict['Regulator Volt High']=substationEquipmentTemplate.RegulatorVoltHighOrder
    if(substationEquipmentTemplate.RegulatorVoltLowOrder):
        BodyDict['Regulator Volt Low']=substationEquipmentTemplate.RegulatorVoltLowOrder
    if(substationEquipmentTemplate.RegulatorVoltCurrentOrder):
        BodyDict['Regulator Volt Current']=substationEquipmentTemplate.RegulatorVoltCurrentOrder
    if(substationEquipmentTemplate.RegulatorMaxAmpOrder):
        BodyDict['Regulator Max Amp']=substationEquipmentTemplate.RegulatorMaxAmpOrder
    if(substationEquipmentTemplate.SurgeProtectorVisualOrder):
        BodyDict['Surge Protector Visual']=substationEquipmentTemplate.SurgeProtectorVisualOrder
    if(substationEquipmentTemplate.TransformerOilLeakOrder):
        BodyDict['Transformer Oil Leak']=substationEquipmentTemplate.TransformerOilLeakOrder
    if(substationEquipmentTemplate.TransformerNitrogenPressureOrder):
        BodyDict['Transformer Nitrogen Pressure']=substationEquipmentTemplate.TransformerNitrogenPressureOrder
    if(substationEquipmentTemplate.TransformerOilVisualOrder):
        BodyDict['Transformer Oil Visual']=substationEquipmentTemplate.TransformerOilVisualOrder
    if(substationEquipmentTemplate.TransformerOilTemperatureCurrentOrder):
        BodyDict['Transformer Oil Temperature Current']=substationEquipmentTemplate.TransformerOilTemperatureCurrentOrder
    if(substationEquipmentTemplate.TransformerOilTemperatureMaximumOrder):
        BodyDict['Transformer Oil Temperature Maximum']=substationEquipmentTemplate.TransformerOilTemperatureMaximumOrder
    if(substationEquipmentTemplate.TransformerWindingTemperatureCurrentOrder):
        BodyDict['Transformer Winding Temperature Current']=substationEquipmentTemplate.TransformerWindingTemperatureCurrentOrder
    if(substationEquipmentTemplate.TransformerWindingTemperatureMaximumOrder):
        BodyDict['Transformer Winding Temperature Maximum']=substationEquipmentTemplate.TransformerWindingTemperatureMaximumOrder
    if(substationEquipmentTemplate.MechanismChargeOrder):
        BodyDict['Mechanism Charge']=substationEquipmentTemplate.MechanismChargeOrder
    if(substationEquipmentTemplate.OperationCounterOrder):
        BodyDict['Operation Counter']=substationEquipmentTemplate.OperationCounterOrder
    if(substationEquipmentTemplate.FanWorkingVisualOrder):
        BodyDict['Fan Working Visual']=substationEquipmentTemplate.FanWorkingVisualOrder
    if(substationEquipmentTemplate.DemandAmpAOrder):
        BodyDict['Demand Amp A']=substationEquipmentTemplate.DemandAmpAOrder
    if(substationEquipmentTemplate.DemandAmpBOrder):
        BodyDict['Demand Amp B']=substationEquipmentTemplate.DemandAmpBOrder
    if(substationEquipmentTemplate.DemandAmpCOrder):
        BodyDict['Demand Amp C']=substationEquipmentTemplate.DemandAmpCOrder
    if(substationEquipmentTemplate.OverCurrentTripOrder):
        BodyDict['Over Current Trip']=substationEquipmentTemplate.OverCurrentTripOrder
    if(substationEquipmentTemplate.BreakerCounterOrder):
        BodyDict['Breaker Counter']=substationEquipmentTemplate.BreakerCounterOrder
    BodyDictItems=BodyDict.items()
    BodyDictItems.sort(key=lambda x: x[1])
    BodyList=[]
    for i in BodyDictItems:
        if('Operation Counter' in i):
            BodyList.append('<tr><td>' + i[0] + ' {{form.' + i[0].replace(' ', '') + '}}</td><td>{{InspectionListString}}</td></tr>\n')
        else:
            BodyList.append('<tr><td>' + i[0] + ' {{form.' + i[0].replace(' ', '') + '}}</td></tr>\n')
    Body=''.join(BodyList)
    return Header + Body + Footer
        

